hls直播nginx配置

2.nginx配置

Nginx可以支持多虚机配置,如果是一个ip或域名多虚机的情况,就是要不同的虚机对应不同的端口服务,而如果是多ip或域名一个虚机的情况,则又不一样。这里的实际情况就是,80和8080分别对应一个http协议的虚机,1935对应一个rtmp协议的虚机。关于hls具体配置项的解释参见

https://github.com/arut/nginx-rtmp-module/wiki/Directives

在原有的nginx.conf中加入如下配置

rtmp {

    server {

        listen 1935;

        chunk_size 4000;
      
        #HLS

        # For HLS to work please create a directory in tmpfs (/tmp/app here)
        # for the fragments. The directory contents is served via HTTP (see
        # http{} section in config)
        #
        # Incoming stream must be in H264/AAC. For iPhones use baseline H264
        # profile (see ffmpeg example).
        # This example creates RTMP stream from movie ready for HLS:
        #
        # ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264 
        #    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1 
        #    -f flv rtmp://localhost:1935/hls/movie
        #
        # If you need to transcode live stream use 'exec' feature.
        #
        application hls {
            live on;
            hls on;
            hls_path /usr/local/nginx/html/hls;
            hls_fragment 5s;
        }
    }
}

http {

    server {

        listen  8080;
        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root html;
            expires -1;
        }
    }
}

其中rtmp部分与原有的http部分在同一个级别,但是下面的http部分要放到已有的http部分中,也就是增加一个server部分。
然后运行如下命令检查nginx.conf是否有语法错误
service nginx configtest
重新加载配置文件
service nginx reload
运行下面的命令查看nginx状态
service nginx status
然后查看端口
netstat -nlp
注意,这里reload并不能开启这几个服务,需要使用
service nginx restart
来将rtmp服务和hls服务的端口1935和8080都打开,参看下面的截图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值