0、 配置:centos7.9 64bit
1、 下载必要库
yum -y install wget yum -y install gcc gcc-c++ yum -y install openssl yum -y install openssl-devel yum -y install pcre yum -y install pcre-devel yum -y install zlib yum -y install git
2、 克隆rtmp模板库以及nginx安装
获取nginx软件压缩包并解压
cd /usr/local/
git clone https://github.com/arut/nginx-rtmp-module.git
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz
安装nginx
cd /usr/local/nginx-1.20.1/
./configure --prefix=/usr/local/src/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module --add-module=/usr/local/nginx-rtmp-module --with-http_ssl_module
-
下图代表成功  -
配置nginx.config文件
make
make install
vim /usr/local/src/nginx/conf/nginx.conf
- 配置路径(在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL下添加)
vim /etc/profile

export NGINX_HOME=/usr/local/src/nginx
export PATH=$PATH:$NGINX_HOME/sbin
source /etc/profile
nginx -v
- 输出为:nginx version: nginx/1.20.1
- 启动nginx
nginx
-
打开浏览器输入服务器ip看到下面页面则配置成功  -
(nginx重启命令)
nginx -s reload
nginx -V

配置端口
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT
vim /usr/local/src/nginx/conf/nginx.conf

rtmp {
server {
listen 1935;
chunk_size 4000;
application test {
live on;
hls on;
hls_path /usr/local/src/nginx/html/test;
hls_fragment 5s;
}
}
}
nginx -s reload
lsof -i tcp:1935

- 用telnet访问1935端口,然后在服务器再次输入lsof -i tcp:1935
#cmd
Telnet ip port
lsof -i tcp:1935

3、 推拉流测试
- 推流使用obs
服务器地址格式为rtmp://ip_address/appname - 拉流使用potplayer
拉流地址为 http://ip_address/appname/stream.m3u8 
4、 参考链接:
搭建基于nginx的rtmp直播服务器
|