如何修复RTMP_Connect0,无法连接套接字。 111(连接被拒绝)?

时间:2019-04-26 00:01:51

标签: nginx rtmp nginx-config

尝试将m3u8流源推送到Nginx RTMP服务器时出现此错误

这是我的FFmpeg命令

ffmpeg -re -i https://xxxxxxxxxxxxxxx.akamaihd.net/hls/live/621275/1539097700001/master_1080p.m3u8 -c:v copy -c:a aac -ar 44100 -ab 128k -ac 2 -strict -2 -flags +global_header -bsf:a aac_adtstoasc -bufsize 700k -f flv rtmp://xx.xxx.xx.156/tmp/hls/stream

这是我的Nginx conf文件:

#user  nobody;
worker_processes  1;
error_log  logs/rtmp_error.log debug;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    server {
        listen       80;
        server_name  localhost;
        location /hls {
            # Serve HLS fragments
            # CORS setup
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length';
            # allow CORS preflight requests
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;
        }
    }
}
rtmp {
        server {
                listen 1935;
                chunk_size 8192;
                application hls {
                        live on;
                        meta copy;
                        hls on;
                        hls_path /tmp/hls/stream;
        }
    }
}

我认为这清楚地表明了我的问题。 如果有人知道,请随时发表评论。

致谢

1 个答案:

答案 0 :(得分:1)

防火墙的1935端口未打开。

打开端口:

firewall-cmd --permanent --add-service=http # permanently enable HTTP connections on port 80
firewall-cmd --zone=public --add-port=1935/tcp --permanent
firewall-cmd --list-ports    # check
firewall-cmd --reload

有关在Centos中构建ffmpeg的整个流程,请参见我的教程,https://github.com/magictomagic/magictomagic.github.io/blob/master/_posts/2020-05-04-CentOS-FFmpeg-%E6%B5%81%E5%AA%92%E4%BD%93%E6%92%AD%E6%94%BE.md

环境是CentOS 8。