nginx扩展nginx-rtmp-module搭建流媒体直播

系统环境: CentOS 8.1.1911  最小化+开发工具

更换yum源为阿里云

mv /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.backup

wget -O /etc/yum.repos.d/CentOS-Base.repo  http://mirrors.aliyun.com/repo/Centos-8.repo

yum makecache

关闭firewalld和selinux

systemctl disable firewalld.service

sed -i 's/SELINUX=enforcing/SELINUX=disabled/'   /etc/selinux/config

reboot

安装环境依赖

yum groupinstall 'Development Tools' -y

yum install epel-release -y

yum install -y git unzip perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 gd-devel GeoIP GeoIP-devel GeoIP-data

下载组件文件

wget http://nginx.org/download/nginx-1.18.0.tar.gz

wget https://ftp.pcre.org/pub/pcre/pcre-8.42.zip

wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz

tar -xzvf openssl-1.1.0h.tar.gz

unzip pcre-8.42.zip

tar -xvzf nginx-1.18.0.tar.gz

git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git

nginx安装

cd nginx-1.18.0

./configure --prefix=/usr/local/nginx \
--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=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--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 \
--http-client-body-temp-path=/usr/local/nginx/client_temp \
--http-proxy-temp-path=/usr/local/nginx/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/scgi_temp \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre-jit \
--with-pcre=../pcre-8.42 \
--with-openssl=../openssl-1.1.0h \
--with-openssl-opt=no-nextprotoneg \
--add-module=../nginx-rtmp-module \
--with-debug

make

make  install

测试启动

/usr/local/nginx/sbin/nginx

ss -tnlp | grep nginx

配置RTMP

vi /usr/local/nginx/conf/nginx.conf

worker_processes auto;
events {
worker_connections 1024;
}

# RTMP configuration
rtmp {
server {
listen 1935;   #推流监听端口
chunk_size 4000;
application yuchen {
live on;
hls on;
hls_path  /usr/local/nginx/html/yuchen;
hls_fragment 10s;
}
}
}

http {
sendfile off;
tcp_nopush on;
aio on;
directio 512;
default_type application/octet-stream;
    server {  
        listen       1936;   #拉流监听端口 
        server_name  localhost;
        location / {  
        add_header Cache-Control no-cache;
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
        add_header 'Access-Control-Allow-Headers' 'Range';
            root   /usr/local/nginx/html/;  
            index  index.html index.htm;  
        }  
      
        #error_page  404      /404.html;  
        # redirect server error pages to the static page /50x.html  
        error_page   500 502 503 504  /50x.html;  
        location = /50x.html {  
            root   html;  
        }
  } 
}

pkill -9 nginx

/usr/local/nginx/sbin/nginx

ss -tnlp | grep nginx

推流地址

rtmp://ip:1935/yuchen/

串流密钥yuchen

(这里使用工具OBS-Studio-26.1.1-Full-Installer-x64.exe进行推流,当然EV录屏也可以)

在potplayer中播放http的m3u8地址。或者是使用支持rtmp协议的播放器拉流

拉流地址

http://ip:1936/yuchen/yuchen.m3u8

 

完事!

注意:

  1. rtmp{}的内容和http{}为同级,位置不要放错。
  2. 苹果系统原生H5支持m3u8,直接浏览器播放即可。
  3. 会存在3-5分钟的延时。

参考文献

1.https://www.atlantic.net/vps-hosting/how-to-install-nginx-with-rtmp-module-on-centos-8/

2.通过nginx扩展nginx-rtmp-module简单做了一个流媒体直播-博客园

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值