基于nginx的rtmp直播服务器(nginx-rtmp-module实现)

一、安装加载nginx-rtmp-module模块的nginx

1、到nginx.org 下载稳定版本的nginx

 2、到 https://github.com/arut/nginx-rtmp-module 下载rtmp模块(git clone https://github.com/arut/nginx-rtmp-module.git)

解压nginx的tar包;nginx 和trmp模块在同一目录

nginx-1.12.2  nginx-1.12.2.tar.gz  nginx-rtmp-module

3、到nginx解压目录配置编译参数

./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module.1.1.4 --with-http_ssl_module 

4、make && make install 安装

如果已安装nginx可以在已有nginx上面增加模块:参考https://www.cnblogs.com/zhangmingda/p/12622590.html

二、配置nginx rtmp直播功能nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on; #内核直接发送文件到客户端
    tcp_nopush          on; #够一定数据量再发送
    tcp_nodelay         on; #同上
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
#        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {
            resolver 8.8.8.8;
            #proxy_pass $scheme://$http_host$request_uri;
            proxy_buffers   256 4k;                         
            proxy_max_temp_file_size 0k; 
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
    server {
        listen       443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        ssl_certificate "/etc/pki/nginx/server.crt";
        ssl_certificate_key "/etc/pki/nginx/private/server.key";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    server {
    listen 8080;
        #配置TRMP状态查看界面================================ 
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root /opt/rtmp/nginx-rtmp-module/; 
        }
        #TRMP状态界面配置结束=================================
    }

}
#点播功能实现配置和http同级别
rtmp {
    server {
        listen 1935; #默认端口1935
        chunk_size 4000;
        application vod {
            play /usr/share/nginx/html/vod/flvs/;#点播媒体存放目录
        }
        application live {   #直播媒体流应用
            live on;
        }
    }
}

1、点播
  
1.1 mkdir /usr/share/nginx/html/vod/flvs/;#创建点播媒体存放目录,并存放test.flv 视频文件
  1.2 访问点播资源
    html页面嵌入wplayer播放器。播放器播放rtmp://....资源
基于nginx的rtmp直播服务器(nginx-rtmp-module实现)
 1 <html>
 2          <head>
 3          welcome test rtmp <br>
 4                    <script src="/jwplayer/jwplayer.js"></script>
 5          </head>
 6          <body>
 7          <script type="text/javascript">
 8                             jwplayer.key="gq5NkJHPa+/FmgFfssKaHtp4gbzJJzcRhES+H9Cs4w8=";
 9                    </script>
10                    <div id='my-video'></div>
11                    <script type='text/javascript'>
12                             jwplayer('my-video').setup({
13                                      file:'rtmp://120.92.91.16/vod/test.flv',   
14                                      width:'50%',
15                                      aspectratio:'3:2',
16                                      fallback:'false',
17                                      primary:'flash' 
18                                      });
19                    </script>
20                    <script type="text/javascript">
21                             jwplayer.key="gq5NkJHPa+/FmgFfssKaHtp4gbzJJzcRhES+H9Cs4w8=";
22                    </script>
23          </body>
24 </html>
html+wplayer播放器播放流媒体

 

 





 

 

上一篇:如何实现RTMP推送Android Camera2数据


下一篇:Android中实现静态的默认安装和卸载应用