1. 程式人生 > >Nginx 自帶模塊構建流媒體服務

Nginx 自帶模塊構建流媒體服務

gunzip graph linux oot mat zha spdy cli res

Nginx 部署流媒體服務

Nginx 平滑升級

參考地址

http://zhangge.net/4856.html

主機名

IP地址

Ngin版本

系統版本

備註

Nginx-Streaming-media

192.168.1.180

nginx/1.9.4

Cenots6.6

V1

1.軟件依賴環境
yum –y install  gcc* make GeoI GeoIP-data GeoIP-devel  zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libxslt libxslt-devel  gd  gd-devel pcre-devel pcre
 
註釋: # Libxml2是個C語言的XML程式庫,能簡單方便的提供對XML文件的各種操作,並且支持XPATH查詢,及部分的支持XSLT轉換等功能!
未安裝GeoI GeoIP-data GeoIP-devel gd-devel  依賴包會出現
#編譯出現以下報錯信息;
出現./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.
2. NGINX源碼包安裝;
1.在線下載官方軟件
wget  http://nginx.org/download/nginx-1.9.4.tar.gz
tar xf  nginx-1.*.tar.gz  -C  /usr/local/src
cd  /usr/local/ nginx-1.9.4

2.添加編譯詳細參數;
./configure --prefix=/usr/loal/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --http-client-body-temp-path=$nginx_tmp/client --http-proxy-temp-path=$nginx_tmp/proxy --http-fastcgi-temp-path=$nginx_tmp/fcgi --http-uwsgi-temp-path=$nginx_tmp/uwsgi --http-scgi-temp-path=$nginx_tmp/scgi  --with-pcre
make && make install


3.NGINX核心配置部分
## nginx main configure file
user nginx nginx;
#worker_processes _PROCESSES;
worker_priority -10;
worker_rlimit_nofile 51200;
error_log  _ERROR_LOG error; 
pid        /var/run/nginx.pid;
#access_log off;
#access_log /var/log/nginx/access.log combined; 
events {
  use epoll;
    worker_connections  51200;
}
http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;
charset utf-8;
 
server_tokens   off;
server_names_hash_bucket_size 256;
 client_header_buffer_size 256k;
 large_client_header_buffers 4 256k;
client_max_body_size 50m;
client_body_buffer_size 256k;
 client_header_timeout 3m;
 client_body_timeout 3m;
sendfile       on;
tcp_nopush     on;
keepalive_timeout  120;
 tcp_nodelay on;
 gzip on;
gzip_min_length 1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    include nginx_cache/*.conf;
} 
server {
        listen       80;
       server_name  www.test123.com;
       charset  utf-8;
       access_log  /var/log/nginx/host.access.log  main;
    location / {
         root /home/medio/project/;
         index  index.html index.htm;
      }
     location ~ .*\.(mp4|jpg)$             
         {
             root /home/medio/project/;
              limit_rate_after 500k;
              limit_rate 128k;
              expires 30d; 
        valid_referers none blocked www.breaklinux.com breaklinux.com *.test123.com;
            if ($invalid_referer) {
                    rewrite ^/ http://www.test123.com/retrun.html;
                 return 403;
            }
          }
      
}
server {
  listen 80;
  server_name    www.wenjian123.com;
  root /home/medio/test;
  index index.html;
}
 
4. 測試流媒體服務;
上傳MP4格式視頻文件。放置nginx索引目錄下;訪問如下;


技術分享圖片

Nginx 自帶模塊構建流媒體服務