Nginx Streaming Media Support configuration

Source: Internet
Author: User
Tags openssl

Nginx is a short, very powerful Web server that can also be used as a reverse proxy server and a mail server. In addition Nginx can also be used to build a simple streaming media server. Based on this, this article describes the construction of a simple streaming media server on top of Nginx 1.8, and proxies it to a streaming media server by means of a reverse proxy.

Basic knowledge related to Nginx
Linux 6 Install compile install Nginx
Nginx Overview and Day-to-day management
Nginx based on IP, port, domain name configuration virtual Host
Linux configuration Nginx to PHP connection One, the current operating environment and installation files

1, the current operating environment
# more/etc/redhat-release 
CentOS Release 6.5 (Final)

#/u01/app/nginx/sbin/nginx-v
nginx version:nginx/1.8.1

2, installation file download
http://download.csdn.net/detail/robinson_0612/9738948

3, installation file location
# PWD
/u01/soft

# ls
yamdi-1.9.tar.gz      nginx_mod_h264_streaming-2.2.7.tar.gz      nginx-1.8.1
Ii. Installation and recompilation of Nginx
1. Installation Yamdi # TAR-XF yamdi-1.9.tar.gz # CD yamdi-1.9 # make && make install Gcc-o2-wall yamdi.c-o yamdi Install-m 0755-o root yamdi/usr/local/bin 2, installation nginx_mod_h264_streaming # cd/u01/soft # tar-xf Nginx_mod_h26 4_streaming-2.2.7.tar.gz # vim/u01/soft/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c ###
    Comment out 158-161 lines 157/* TODO:WIN32 * * 158//if (R->zero_in_uri) 159 {160 return ngx_declined; 161} 162 * * # #否则出现如下错误 # 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: In the function ' Ngx_streaming_handler ':/usr/local/src/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_ module.c:158: Error: ' ngx_http_request_t ' does not have a member named ' Zero_in_uri ' make[1]: * * * [objs/addon/src/ngx_http_h264_streaming_ MODULE.O] Error 1 Make[1]: Leaving directory '/usr/local/src/nginx-1.8.1 ' make: ** * [Build] Error 2 3, view Nginx currently compiled module and add module #/u01/app/nginx/sbin/nginx-v nginx version:nginx/1.8.1 built by GCC 4.4.7 2012 
        0313 (Red Hat 4.4.7-17) (GCC) built with OpenSSL 1.0.1e-fips one 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-te 
        Mp-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--wit H-http_realip_module--wiTh-http_addition_module--with-http_sub_module--with-http_dav_module--with-http_flv_module--with-http_mp4_modu Le--with-http_gunzip_module--with-http_gzip_static_module--with-http_random_index_module--with-http_secure_li 
        Nk_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 \--ht tp-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/uw Sgi_temp \--http-scgi-temp-path=/u01/app/nginx/tempcache/scgi_temp--us Er=nginx--group=nginx \--with-http_ssl_module--with-http_realip_module--with-http_addition_mo Dule--with-http_sub_module \--with-http_dav_module--with-http_flv_module--with-http_mp4_module--with-http_gu                Nzip_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 Add Module # make #/u01/app/nginx/sbin/nginx-s Stop # Cp/u01/app/nginx/sbin/ng inx/u01/app/nginx/sbin/nginx.bk.0116 ### replace nginx binary file # cp/u01/soft/nginx-1.8.1/objs/nginx/u01/app/nginx/sbin/ Nginx # service Nginx start starting nginx: [OK] #/u01/app/nginx/sbin/ng Inx-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/sof. t/nginx_mod_h264_streaming-2.2.7
Three, Nginx profile excerpt (for reference)
### nginx configuration File # 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" $htt

        "P_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:2000m inactive=10d max_s

        ize=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 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 Upstre
    Am 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; } # # # #测试 Http://www.abc.com/stream/test.mp4
iv. Dynamic increase of Nginx module
NGINX 1.9.11 began adding support for dynamic modules, and it was no longer necessary to replace NGINX files to increase Third-party extensions.
at present, only a few of the official modules to support dynamic loading, third-party modules need to upgrade support to compile into a module.

#./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=                  the PATH enable dynamic external module

shows that the official support for 5 dynamic module compilation, the need to add Third-party modules, the use of parameter--add-dynamic-module= can be.

nginx Dynamic Module syntax, this configuration method is similar to the Apache httpd
        load_module

        default:-

        configuration segment: Main

        Description: version must be >=1.9.11

        Example:
                load_module modules/ngx_mail_module.so;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.