Nginx流媒体支持配置
生活随笔
收集整理的這篇文章主要介紹了
Nginx流媒体支持配置
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Nginx是一個(gè)短小精悍,且性能超強(qiáng)的Web服務(wù)器,同時(shí)也可以用作反向代理服務(wù)器以及郵件服務(wù)器。除此之外Nginx也可以用于搭建一個(gè)簡(jiǎn)易的流媒體服務(wù)器?;诖?#xff0c;本文描述了在Nginx 1.8之上構(gòu)建一個(gè)簡(jiǎn)易的流媒體服務(wù)器,同時(shí)通過(guò)反向代理的方式將其代理至流媒體服務(wù)器。
有關(guān)Nginx相關(guān)的基礎(chǔ)知識(shí)
Linux 6下安裝編譯安裝Nginx
Nginx 概述及日常管理
Nginx基于IP,端口,域名配置虛擬主機(jī)
Linux 下配置nginx到php的連接
一、當(dāng)前的運(yùn)行環(huán)境及安裝文件
1、當(dāng)前的運(yùn)行環(huán)境 # more /etc/redhat-release CentOS release 6.5 (Final)# /u01/app/nginx/sbin/nginx -v nginx version: nginx/1.8.12、安裝文件下載 http://download.csdn.net/detail/robinson_0612/97389483、安裝文件位置 # pwd /u01/soft# ls yamdi-1.9.tar.gz nginx_mod_h264_streaming-2.2.7.tar.gz nginx-1.8.1二、安裝及重新編譯Nginx
1、安裝yamdi # tar -xf yamdi-1.9.tar.gz # cd yamdi-1.9 # make && make installgcc -O2 -Wall yamdi.c -o yamdiinstall -m 0755 -o root yamdi /usr/local/bin2、安裝nginx_mod_h264_streaming # cd /u01/soft # tar -xf nginx_mod_h264_streaming-2.2.7.tar.gz # vim /u01/soft/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c###注釋掉158-161行157 /* TODO: Win32 */158 /* if (r->zero_in_uri)159 {160 return NGX_DECLINED;161 }162 */ ###否則出現(xiàn)如下錯(cuò)誤 # make In file included from /usr/local/src/nginx_mod_h264_streaming-2.2.7/src/ngx_http_h264_streaming_module.c:2: /usr/local/src/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c: 在函數(shù)‘ngx_streaming_handler’中: /usr/local/src/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c:158: 錯(cuò)誤: ‘ngx_http_request_t’沒(méi)有名為‘zero_in_uri’的成員 make[1]: *** [objs/addon/src/ngx_http_h264_streaming_module.o] 錯(cuò)誤 1 make[1]: Leaving directory `/usr/local/src/nginx-1.8.1' make: *** [build] 錯(cuò)誤 23、查看nginx當(dāng)前已編譯的模塊以及添加模塊 # /u01/app/nginx/sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/u01/app/nginx --sbin-path=/u01/app/nginx/sbin/nginx --conf-path=/u01/app/nginx/conf/nginx.conf --error-log-path=/u01/app/nginx/logs/error.log --http-log-path=/u01/app/nginx/logs/access.log --pid-path=/u01/app/nginx/nginx.pid --lock-path=/u01/app/nginx/nginx.lock --http-client-body-temp-path=/u01/app/nginx/tempcache/client_temp --http-proxy-temp-path=/u01/app/nginx/tempcache/proxy_temp --http-fastcgi-temp-path=/u01/app/nginx/tempcache/fastcgi_temp --http-uwsgi-temp-path=/u01/app/nginx/tempcache/uwsgi_temp --http-scgi-temp-path=/u01/app/nginx/tempcache/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_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_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-ipv6 ###將nginx_mod_h264_streaming模塊添加到nginx # cd /u01/soft/nginx-1.8.1 # ./configure \ --prefix=/u01/app/nginx --sbin-path=/u01/app/nginx/sbin/nginx \ --conf-path=/u01/app/nginx/conf/nginx.conf --error-log-path=/u01/app/nginx/logs/error.log \ --http-log-path=/u01/app/nginx/logs/access.log --pid-path=/u01/app/nginx/nginx.pid \ --lock-path=/u01/app/nginx/nginx.lock --http-client-body-temp-path=/u01/app/nginx/tempcache/client_temp \ --http-proxy-temp-path=/u01/app/nginx/tempcache/proxy_temp \ --http-fastcgi-temp-path=/u01/app/nginx/tempcache/fastcgi_temp \ --http-uwsgi-temp-path=/u01/app/nginx/tempcache/uwsgi_temp \ --http-scgi-temp-path=/u01/app/nginx/tempcache/scgi_temp --user=nginx --group=nginx \ --with-http_ssl_module --with-http_realip_module --with-http_addition_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_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module \ --with-file-aio --with-http_spdy_module --with-ipv6 \ --add-module=/u01/soft/nginx_mod_h264_streaming-2.2.7 ###使用add-module添加模塊 # make# /u01/app/nginx/sbin/nginx -s stop # cp /u01/app/nginx/sbin/nginx /u01/app/nginx/sbin/nginx.bk.0116### 替換nginx 二進(jìn)制文件 # cp /u01/soft/nginx-1.8.1/objs/nginx /u01/app/nginx/sbin/nginx# service nginx start Starting nginx: [ OK ]# /u01/app/nginx/sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/u01/app/nginx ................ --add-module=/u01/soft/nginx_mod_h264_streaming-2.2.7三、Nginx配置文件摘錄(供參考)
### Nginx配置文件 # more /u01/app/nginx/conf/nginx.conf worker_processes 8; user nobody;error_log /u01/app/nginx/logs/error.log;events {use epoll;worker_connections 65535;multi_accept on; }http {include mime.types;default_type application/octet-stream;charset utf-8;log_format main '$remote_addr [$time_local] "$host $request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';server_names_hash_bucket_size 128;client_header_buffer_size 64k;client_max_body_size 50m;client_body_buffer_size 512k;large_client_header_buffers 4 64k;server_tokens off;sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 10;ssl_session_cache shared:SSL:50m;ssl_session_timeout 5m;proxy_connect_timeout 5;proxy_read_timeout 60;proxy_send_timeout 5;proxy_buffer_size 16k;proxy_buffers 4 64k;proxy_busy_buffers_size 128k;proxy_temp_file_write_size 128k;proxy_temp_path /u01/app/nginx/tempcache/proxy_temp;proxy_cache_path /u01/app/nginx/tempcache/proxy_cache_dir levels=1:2 keys_zone=cache_one:2000minactive=10d max_size=30g;gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_comp_level 6;gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/xml application/xml+rss;open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 2; open_file_cache_valid 30s; open_file_cache_errors on;include conf.d/*.conf; } # more /u01/app/nginx/conf/conf.d/stream.conf server {listen 9091;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root /u02/upload_video;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;} }###反向代理端的配置 # /opt/nginx/sbin/nginx -v nginx version: nginx/1.5.13 # more /opt/nginx/conf/conf.d/http-www.conf upstream stream_srv {server 10.24.249.21:9091 max_fails=3 fail_timeout=30s;keepalive 32; }server {listen 80;server_name www.abc.com;access_log /log/nginx/http-access.log;error_log /log/nginx/http-error.log;location /stream {proxy_set_header Host $host;proxy_set_header x-for $remote_addr;proxy_set_header x-server $host;proxy_set_header x-agent $http_user_agent;proxy_pass http://stream_srv;} }###測(cè)試 http://www.abc.com/stream/test.mp4四、Nginx模塊動(dòng)態(tài)增加
NGINX 1.9.11開(kāi)始增加加載動(dòng)態(tài)模塊支持,從此不再需要替換nginx文件即可增加第三方擴(kuò)展。 目前官方只有幾個(gè)模塊支持動(dòng)態(tài)加載,第三方模塊需要升級(jí)支持才可編譯成模塊。# ./configure --help | grep dynamic--with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module--with-http_image_filter_module=dynamic enable dynamic ngx_http_image_filter_module--with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module--with-mail=dynamic enable dynamic POP3/IMAP4/SMTP proxy module--with-stream=dynamic enable dynamic TCP proxy module--add-dynamic-module=PATH enable dynamic external module如上可看出官方支持5個(gè)動(dòng)態(tài)模塊編譯,需要增加第三方模塊,使用參數(shù)--add-dynamic-module=即可。NGINX動(dòng)態(tài)模塊語(yǔ)法,此配置方法和Apache httpd大同小異load_moduleDefault: —配置段: main說(shuō)明:版本必須>=1.9.11示例:load_module modules/ngx_mail_module.so;總結(jié)
以上是生活随笔為你收集整理的Nginx流媒体支持配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux快速查看某条命令的版本和存放的
- 下一篇: [转]ESP8266使用详解