Use nginx Rtmp Module to build your own live server

Download source code

First prepare the source code and commonly used compilation tools (gcc and the like)

mkdir /opt/git # 这里我偷懒直接把源码下载到这了,大家自行找地方
cd /opt/git
git clone https://github.com/arut/nginx-rtmp-module.git # 下载 nginx-rtmp-module
wget http://nginx.org/download/nginx-1.17.7.tar.gz # 下载nginx,这里用的最新测试版,推荐大家用稳定版
tar -zxvf nginx-1.17.7.tar.gz
cd nginx-1.17.7/
./configure --prefix=/opt/nginx1.17 --add-module=/opt/git/nginx-rtmp-module # 这里是重点,添加了一个mod
make && make install # 编译安装
cd /opt/nginx1.17/
vim /opt/nginx1.17/conf/nginx.conf # 开始配置
# 全部注释或删除 /opt/nginx1.17/conf/nginx.conf 中的配置
# 在配置的最高层,可以是开头或结尾,添加下面的包含
include rtmp.conf

Edit rtmp configuration file

vim /opt/nginx1.17/conf/rtmp.conf

Add the following configuration

rtmp {
    server {
        listen 8883;  # 我使用的自定义端口,而不是标准的1935

        application vod {
            play /opt/nginx1.17/video;
        }

        application live{ #第一处添加的直播字段,添加了一个live应用,里面可以有很多直播间
            live on;
        }
    }
}

http {
    #include      mime.types;
    #default_type  application/octet-stream;
    #sendfile        on;
    #keepalive_timeout  65;
    server {
        listen      8884; #用于查看直播状态和观看直播的web页面
        server_name  localhost;

        location /stat { # 状态查看页面实例
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
           root /opt/git/nginx-rtmp-module/;
        }
	
	location /control {
            rtmp_control all;
        }

	location /rtmp-publisher {
            root /opt/git/nginx-rtmp-module/test;
        }
	
	location / { # 直播观看页面实例
            root /opt/git/nginx-rtmp-module/test/www;
        }

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

Turn on the firewall

firewall-cmd --add-port=8883/tcp
firewall-cmd --add-port=8883/udp
firewall-cmd --add-port=8884/tcp
firewall-cmd --add-port=8884/udp

So far the server is built

use

obs push to
rtmp://[ip address]:8883/live

Check the push status on the webpage
http://[ip address]:8884/stat

On-demand video is placed in
/opt/nginx1.17/video of the server

vnc view the stream, open the network URL
rtmp://[ip address]:8883/live

View push streaming and on-demand videos on the web, but you will not use
http://[ip address]:8884

Guess you like

Origin blog.csdn.net/zoollcar/article/details/104814367