nginx搭建點播視頻(Mp4播放)

首先,環境中必然要有gcc-c++環境javascript

  yum -y install gcc-c++html

1 使用openrestyhtml5

這裏使用的是1.11.2.1版本的openresty和1.0.2版本的openssljava

      root@King: ~#yum install readline-devel pcre-devel openssl-devel gcc

      root@King: ~# tar -zxvf openresty-1.11.2.1.tar.gz

      root@King: ~#tar -zxvf openssl-1.0.2h.tar.gz

      root@King: ~#cd openresty-1.11.2.1

      root@King: ~#./configure --prefix=/app/openresty --user=xxx --group=xxx --with-http_v2_module --with-openssl=/home/appdeploy/nginx/openssl-1.0.2h --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module

 

能夠在這裏設置user和group,也能夠稍後使用下面的命令進行設置node

chown -R [user]:[group] 文件夾名上面的命令執行以後,編譯並安裝openrestry,安裝目錄就是配置中指定的/app/openrestrynginx

   root@King: ~#make && make install

 

若是安裝的時候沒有權限,能夠用su切到root,注意安裝以後的openrestry目錄的權限便可。
此時openrestry已經安裝好,到安裝目錄中修改openrestry下的nginx文件夾下的nginx.conf配置文件c++

worker_processes 1;       #工做進程數,通常設置爲1就能夠了
#error_log  /usr/local/nginx/logs/error.log  crit;
#pid        /usr/local/nginx/logs/nginx.pid;
events {
        use epoll;
        worker_connections      65535;
        }
http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format main  '$remote_addr - $remote_user [$time_local] '
                                                '"$request" $status $bytes_sent '
                                                '"$http_referer" "$http_user_agent" '
                                                '"$gzip_ratio"';
        keepalive_timeout  60;
        server_names_hash_bucket_size  128;
        client_header_buffer_size    32k;
        large_client_header_buffers  4 32k;
        access_log off;
        gzip on;
        gzip_min_length  1100;
        gzip_buffers     4 8k;
        gzip_types       text/plain;
        output_buffers   1 32k;
        postpone_output  1460;
        client_header_timeout  3m;
        client_body_timeout    3m;
        send_timeout           3m;
        sendfile                on;
        tcp_nopush              on;
        tcp_nodelay             on;
    server {
           listen 8080;
           server_name  10.202.94.16;
           root    /app/openresty/nginx/html/;
           limit_rate_after 30m;   
           limit_rate 700k;            #這裏根據須要設置,意思是視頻緩衝30M以後,限速爲700k/s
           index   index.html;
           charset utf-8;
           location ~ \.flv$ {
              flv;
           }
           location ~ \.mp4$ {
              mp4;
           }
           error_page   500 502 503 504  /50x.html;
           location = /50x.html {
               root   html;
           }
    }
}

 

修改以後,啓動nginx服務器ubuntu

  root@King: ~#/app/openresty/nginx/sbin/nginx -c /app/openresty/nginx/conf/nginx.conf

將mp4文件放到/app/openresty/nginx/html/目錄下
在瀏覽器上訪問http://10.202.94.16:8080/xxx.mp4便可。瀏覽器

2 使用nginx服務器

建議採用nginx 1.1.3版本以後的nginx,默認支持mp4,就無需再安裝一堆繁瑣的插件。這裏使用的是1.3.14版本。

  root@King: ~# tar -zxvf nginx-1.3.14.tar.gz

  root@King: ~# cd nginx-1.3.14

  root@King: ~# ./configure --prefix=/app/nginx --user=xxx --group=xxx --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module

  root@King: ~# make&& make install

 

而後一樣的,去/app/nginx作和openrestry中的nginx同樣的修改便可,注意修改目錄。

效果以下所示,此時的視頻是橫跨整個屏幕的,若是想要修改,好比作頁面的內嵌視頻,能夠把視頻放到HTML5頁面中,再經過nginx服務器訪問html文件便可。有個開源的video.js很好用,這裏就再也不贅述了。

 

報錯信息處理:


http://nginx.org/download/nginx-1.9.15.tar.gz 下載nginx包(或者wget http://nginx.org/download/nginx-1.9.15.tar.gz直接在Linux上用命令下載)

解壓並轉到目錄下

  root@King: ~# tar -zxvf nginx-1.9.15.tar.gz
  root@King: ~# cd nginx-1.9.15


設置一下配置信息

  root@King: ~#./configure --prefix=/usr/local/nginx ,或者不執行此步,直接默認配置


編譯安裝

    root@King: ~# make
    root@King: ~# make install


make的過程是把各類語言寫的源碼文件,變成可執行文件和各類庫文件;
make install是把這些編譯出來的可執行文件和庫文件複製到合適的地方。

可能出現錯誤在配置信息

    root@King: ~#./configure --prefix=/usr/local/nginx 的時,出現錯誤:
/configure: error: the HTTP rewrite module requires the PCRE library.

解決方法:安裝pcre
 

 root@King: ~# yum -y install pcre pcre-devel


-y 是跳過全部須要手動確認的環節

缺乏ssl錯誤,錯誤信息以下:
root@King: ~# ./configure
error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system,or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options.


解決方法:安裝openssl

  root@King: ~# yum -y install openssl openssl-devel


缺乏編譯器,錯誤信息以下:

    root@King: ~# ./configure
    error: C compiler cc is not found


解決方法:安裝gcc-c++

    root@King: ~# yum -y install gcc-c++ autoconf automake


autoconf是自動配置,automake是自動編譯
缺乏zlib包,錯誤信息以下:

    root@King: ~# ./configure: 
    error: the HTTP gzip module requires the zlib library.You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib=<path> option.


解決方法:安裝zlib

    root@King: ~# yum install -y zlib-devel


確實libxml2,錯誤信息以下:

    root@King: ~# ./configure: 
    error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.


解決方法:

    root@King: ~# yum -y install libxml2 libxml2-dev
    root@King: ~# yum -y install libxslt-devel


http_image_filter_module是nginx提供的集成圖片處理模塊,須要gd-devel的支持,錯誤信息以下:

    root@King: ~# ./configure: 
    error: the HTTP image filter module requires the GD library.You can either do not enable the module or install the libraries.


解決方法:

    root@King: ~# yum -y install gd-devel


缺乏ExtUtils,錯誤信息以下:

    root@King: ~# ./configure: 
    error: perl module ExtUtils::Embed is required


解決方法:

    root@King: ~# yum -y install perl-devel perl-ExtUtils-Embed


缺乏GeoIP,錯誤信息以下:

    root@King: ~# ./configure:
     error: the GeoIP module requires the GeoIP library.You can either do not enable the module or install the library.


解決方法:

    root@King: ~# yum -y install GeoIP GeoIP-devel GeoIP-data


安裝完成後啓動安裝成功後 /usr/local/nginx 目錄下以下
fastcgi.conf koi-win nginx.conf.default
fastcgi.conf.default logs scgi_params
fastcgi_params mime.types scgi_params.default
fastcgi_params.default mime.types.default uwsgi_params
html nginx uwsgi_params.default
koi-utf nginx.conf win-utf
啓動
確保系統的 80 端口沒被其餘程序佔用,運行/usr/local/nginx/nginx 命令來啓動 Nginx,

    root@King: ~# netstat -ano|grep 80


若是查不到結果後執行,有結果則忽略此步驟(ubuntu下必須用sudo啓動,否則只能在前臺運行)

    root@King: ~# sudo /usr/local/nginx/nginx


打開瀏覽器訪問此機器的 IP,若是瀏覽器出現 Welcome to nginx! 則表示 Nginx 已經安裝並運行成功。

 

 

直播視頻搭建:

rtmp  協議

相關文章
相關標籤/搜索