Nginx RTMP搭建

前言

目录

前言

安装环境

下载nginx

编译安装

设置nginx.conf

重新启动nginx

备用命令

设置开机启动

编写nginx.service

设置开机启动

验证开机启动

最终效果

结束


下面我们介绍使用nginx rtmp模块构建媒体服务器

安装环境

udo apt-get update
sudo apt-get install build-essential libpcre3-dev zlib1g-dev libssl-dev

下载nginx

下载地址  https://nginx.org/en/download.html

tar -zxvf nginx-1.27.0.tar.gz
cd nginx-1.27.0/

编译安装

./configure \
 --with-threads \
 --with-http_stub_status_module \
 --with-http_ssl_module \
 --with-http_realip_module \
 --with-stream \
 --with-stream_ssl_module \
 --add-module=/root/nginx-rtmp-module

make
sudo make install
# 创建了一个符号链接,将 /usr/local/nginx/sbin/nginx 指向 /usr/local/bin/nginx。这样,你可以在终端中直接使用 nginx 命令来启动或管理 Nginx,而不必输入完整的路径
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

设置nginx.conf

http{
    server{
        listen 80;
        server_name localhost;
        location / {
            root html;
            index index.html index.htm;
        }
        location /stat {
            stub_status on;
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root /usr/local/nginx/html;
        }
        location /control {
            rtmp_control all;
        }
    }
}
rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        application live {
            live on;
            hls off;
        }
    }
}

移动stat.xsl文件,方便配置

sudo cp /root/nginx-rtmp-module/stat.xsl /usr/local/nginx/html/

重新启动nginx

sudo nginx -s stop
sudo nginx

备用命令

# 查看端口占用情况
sudo lsof -i :80
sudo lsof -i :1935

设置开机启动

编写nginx.service

sudo nano /etc/systemd/system/nginx.service

加入以下内容

[Unit]
Description=nginx rtmp server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
Restart=on-failure
User=root

[Install]
WantedBy=multi-user.target

重新加载使其生效

sudo systemctl daemon-reload

设置开机启动

sudo systemctl enable nginx

验证开机启动

sudo reboot

最终效果

访问http://10.0.0.127/stat

使用VLC或者OBS播放NginxRTMP上面的流数据

结束

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值