ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2020-04-05 21:03:06  阅读:211  来源: 互联网

标签:http module server nginx html rtmp


一、安装加载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://....资源
 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播放器播放流媒体

 

 





 

 

标签:http,module,server,nginx,html,rtmp
来源: https://www.cnblogs.com/zhangmingda/p/12638985.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有