Nginx直播推流部署

# 下载nginx源码
wget http://nginx.org/download/nginx-1.18.0.tar.gz
# 下载nginx-rtmp模块
git clone https://github.com/arut/nginx-rtmp-module.git
# 安装一些以来
apt install gcc make openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev
# 解包nginx
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0/
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
make && make install
cp -r /root/nginx-rtmp-module/ /usr/local/nginx/nginx-rtmp-module
mkdir hls

vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
systemctl enable nginx.service
systemctl start nginx.service
systemctl status nginx.service
server {
       listen 8080;
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root /usr/local/nginx/nginx-rtmp-module;
        }
        location /live {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            autoindex on;
            expires -1;
            alias /usr/local/nginx/hls;
            add_header Cache-Control no-cache;
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        }
    }

rtmp {
    server {
        listen 1935;
        chunk_size 512;
        application live {
            live on;
            hls on;
            hls_path /usr/local/nginx/hls;
            hls_fragment 3s;
            hls_playlist_length 10s;
            hls_continuous on;
            hls_fragment_naming system;
            hls_cleanup on;
            hls_nested on;
            record all;
            record_path /root/smb/record;
            record_unique on;
        }
    }
}

发表回复

您的电子邮箱地址不会被公开。