Nginx RTMP exec指令无报错但不执行脚本问题咨询
问题
请问是否有方法可以在直播流完成ts切片生成时触发执行脚本?或是在用户连接、开始/停止观看直播流时触发执行对应脚本?
根据NGINX RTMP EXEC 指令官方文档说明:
该类指令用于指定在每次流发布时执行带参数的外部命令,流发布停止时对应进程会被终止,第一个参数需填写二进制文件的完整路径,不对进程的功能做强制限制,常配合ffmpeg实现流转码。
按照文档配置后,所有exec类指令均未触发执行,且/var/log/nginx/error_log中无任何相关错误日志,现寻求排查建议。
注:出于后续业务规划,特意将Nginx运行用户设置为apache而非nginx,当前系统中并未运行apache服务,因此用户名配置不应成为问题诱因。
现有操作与环境说明
- 推流逻辑:通过Windows笔记本向远端服务器推流,推流命令如下,推流功能正常,服务器的
/efsr/5/nginx/hls/teststream路径下可正常生成index.m3u8索引文件和ts切片文件:
ffmpeg.exe -re -i movie.mp4 -c:v libx264 -b:a 128k -crf 23 -strict experimental -f flv rtmp://x.x.x.x:1604/live/teststream
- 测试脚本权限:所有exec类指令均调用同一个测试脚本,脚本权限信息如下:
$ ls -ld /efsr/5/nginx/scripts/nginx_publish_done.sh -rwxr-xr-x 1 apache apache 66 Jul 12 20:01 /efsr/5/nginx/scripts/nginx_publish_done.sh
- 测试脚本内容:仅实现将当前时间追加写入临时文件的简单逻辑:
$ cat /efsr/5/nginx/scripts/nginx_publish_done.sh #!/usr/bin/bash /bin/date >> /tmp/nginx_publish_done.tmp exit 0
- 配置校验结果:已通过
nginx -t校验配置文件,无语法错误:
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
- 已尝试的指令写法:配置校验无错,但尝试多种exec指令写法均无法触发脚本执行,示例写法如下:
exec_publish bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 1"; exec_publish bash -c /efsr/5/nginx/scripts/nginx_publish_done.sh 1; exec_publish /efsr/5/nginx/scripts/nginx_publish_done.sh 1;
完整配置与版本信息
nginx.conf 完整配置
worker_processes auto; user apache; events { worker_connections 1024; } http { server { listen 8080; root /var/www/nginx/hls; location / { index index.html index.htm index.m3u8; } } } # RTMP configuration rtmp { max_connections 200; live on; meta copy; interleave on; wait_key on; idle_streams on; # HLS配置 hls on; hls_type live; hls_path /efsr/5/nginx/hls; hls_fragment 10s; hls_playlist_length 1440m; hls_fragment_naming system; hls_nested on; hls_continuous on; server { listen 1604; chunk_size 4096; buflen 8000ms; application live { live on; wait_key on; wait_video on; publish_notify on; exec_publish bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 1"; exec_publish_done bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 2"; exec_play bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 3"; exec_play_done bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 4"; exec_pull bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 5"; exec_push bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 6"; exec_record_done bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 7"; exec_static bash -c "/efsr/5/nginx/scripts/nginx_publish_done.sh 8"; record off; record_path /var/www/nginx/record; record_suffix -%F.flv; record_unique on; record_interval 15m; record_max_size 100M; } } }
Nginx版本与编译参数
# nginx -V nginx version: nginx/1.23.1 (CentOS) built by gcc 7.3.1 20180712 (Red Hat 7.3.1-15) (GCC) built with OpenSSL 1.1.1q 5 Jul 2022 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=apache --group=apache --build=CentOS --add-module=/usr/local/src/nginx-rtmp-module --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module --with-stream_ssl_preread_module --with-compat --with-pcre --with-pcre-jit --with-zlib=/usr/local/src/zlib-1.2.12 --with-openssl=/usr/local/src/openssl-1.1.1q --with-openssl-opt=no-nextprotoneg --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-debug
内容的提问来源于stack exchange,提问作者Ran Bo
相关产品推荐
相关产品推荐

