nginx 开启 rtmp 和 模块监控模块支持

幻昼 2023年09月06日 124次浏览

默认已经 安装好 nginx,没有就自行 apt 安装

apt update
apt install nginx
安装 nginx rtmp 模块扩展
apt update
apt install libnginx-mod-rtmp
查看是否加载模块
cd /etc/nginx
cat modules-enabled/*.conf
ls modules-enabled/*.conf
配置启用模块
# 切换 root 用户, 
su
vim nginx.conf

# 最外层添加如下 rtmp,vim 使用不懂就网上找吧
rtmp {
	server {
		#流媒体服务器端口
		listen 1935;
		
		application myapp {
			live on;
			#丢弃闲置5s的连接
			drop_idle_publisher 5s;
		}
	}
}

# esc wq 回车退出保存
配置监控网页 server

找一个空闲目录,下载、解压

wget https://codeload.github.com/arut/nginx-rtmp-module/tar.gz/refs/tags/v1.2.2
tar xvf v1.2.2
#得到一个 nginx-rtmp-module-1.2.2 文件夹
cd nginx-rtmp-module-1.2.2
# pwd 得到目录地址,后面 nginx 添加 server 要用到
pwd
cd sites-available/
vim rtmp.conf

# 添加一个新server, 注意地址改为你自己的 nginx-rtmp-module-1.2.2 目录
server {
	#注意端口占用
	listen 8080;
	location /stat {
		rtmp_stat all;
		rtmp_stat_stylesheet stat.xsl;
	}
	
	location /stat.xsl
	{ 
		#注意目录
		root /home/jin/Desktop/rtmp/nginx-rtmp-module-1.2.2/;
	}
	
	location /control
	{ 
		rtmp_control all;
	}
	
	location /rtmp-publisher
	{ 
		#注意目录
		root /home/jin/Desktop/rtmp/nginx-rtmp-module-1.2.2/test;
	}
	
	location / {
		#注意目录
		root /home/jin/Desktop/rtmp/nginx-rtmp-module-1.2.2/test/www;
	}
}

# esc wq 回车退出保存
ln -s /etc/nginx/sites-available/rtmp.conf /etc/nginx/sites-enabled/rtmp.conf

# 测试配置是否有问题, 提升 ok success 就重启 nginx
nginx -t
systemctl restart nginx

打开服务器地址地址即可查看状态

http://192.168.1.xxx:8080/stat

推流地址是:注意端口

rtmp://192.168.1.xxx:1935/myapp