前几天给nginx添加扩展rtmp模块,骚操作删除了很多文件而导致遇到非常多的问题(一般人还真遇不到,哈哈),弄完之后觉得没什么,那会儿还是花了我挺多时间的,给大家分享下
正确的做法
当前有正在运行的nginx,添加rtmp模块:
1.先下载rtmp模块
git clone https://github.com/arut/nginx-rtmp-module.git
2.查看nginx运行的命令, 注意V是大写
nginx -V
把新加的rtmp模块配置到nginx,要在原有的模块设置–add-module=/path to rtmp/
3.进入nginx的源文件目录(有configure文件),然后添加rtmp模块,对nginx再次进行编译
注意,这里不要make install,否则会覆盖
cd /usr/local/src/nginx.1.25.1
./configure --prefix=/usr/local/nginx-1.25.1 --with-openssl=/usr/local/src/openssl-1.0.2s --with-pcre=/usr/local/src/pcre-8.43 --with-zlib=/usr/local/src/zlib-1.2.11 --add-module=/usr/local/nginx-rtmp-module-master --with-http_ssl_module
make
4.配置nginx.conf文件,添加rtmp模块
rtmp {
server {
listen 8787;
chunk_size 4000;
application live {
live on;
record all;
record_path /tmp/av;
record_max_size 1K;
record_unique on;
allow publish all;
deny publish all;
allow play all;
}
}
}
5.重新载入nginx配置文件,重启nginx
nginx -s reload
systemctl restart nginx
6.可以查看是否有绑定上rtmp模块
systemctl status nginx.service
7.一切就绪用OBS Studio测试一下吧
配置场景-显示器采集,设置推流地址
接下来是遇到的一些问题
-bash: /usr/sbin/nginx: 没有那个文件或目录
是/etc/profile 文件配置的Nginx路径问题
使用vim编辑此文件:vim /etc/profile
[emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
显示端口已被占用,杀掉进程即可
netstat -nlp | grep :80
看到进程后杀掉: kill -9 xxxx
-bash: nginx: 未找到命令
可能是修改了/etc/profile文件未重新加载
profile文件重加载: source /etc/profile
Can’t open PID file /var/run/nginx.pid (yet?) after start
出现这种问题是因为nginx服务启动就会搜索nginx.pid文件,但是nginx此时还未创建nginx.pid文件,因此需要睡它一会儿,在/usr/lib/systemd/system/nginx.service加上ExecStartPost=/bin/sleep 0.1 即可
nginx如果起来了,配置nginx.conf也没问题,但是服务访问不了,很可能是防火墙原因