nginx搭建rtmp服务
nginx搭建rtmp服务
使用nginx搭建rtmp服务 。一键安装脚本见 《nginx搭建rmtp服务.sh》
资源
- https://www.cnblogs.com/monjeo/p/8492357.html
- Linux-Nginx+rtmp+ffmpeg搭建流媒体服务器
- 相关搜索技巧 nginx rtmp 组合搜索
安装
准备
从 http://nginx.org/en/download.html 下载nginx
wget http://nginx.org/download/nginx-1.17.6.tar.gz
安装git工具
apt update apt-get install -y git
下载 nginx-rtmp-module
git clone https://github.com/arut/nginx-rtmp-module.git安装依赖
#pcre依赖:libpcre3 libpcre3-dev #zlib依赖:zlib1g-dev #openssl依赖:openssl libssl-dev apt-get install -y libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev
安装
./configure --prefix=/usr/local/bin/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
安装成功,大概会看到如下的输出:
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/bin/nginx"
nginx binary file: "/usr/local/bin/nginx/sbin/nginx"
nginx modules path: "/usr/local/bin/nginx/modules"
nginx configuration prefix: "/usr/local/bin/nginx/conf"
nginx configuration file: "/usr/local/bin/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/bin/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/bin/nginx/logs/error.log"
nginx http access log file: "/usr/local/bin/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
配置
在/usr/local/bin/nginx/conf/nginx.conf最后增加如下:
rtmp {
server {
listen 1935; #监听的端口
chunk_size 4000;
application cctvf { #rtmp推流请求路径 (切记路径错了会推不上流)
live on; #开启实时
hls on; #开启hls
hls_path /usr/local/src/nginx/html/cctvf; #rtmp推流请求路径,文件存放路径
hls_fragment 5s; #每个TS文件包含5秒的视频内容
}
}
}
另外一种配置形式:
rtmp {
server {
listen 1935;
#直播流配置
application rtmplive {
live on;
#为 rtmp 引擎设置最大连接数。默认为 off
max_connections 1024;
}
application hls{
live on;
hls on;
hls_path /usr/local/var/www/hls;
hls_fragment 1s;
}
}
}
启动
假设nginx安装在 /usr/local/bin/nginx目录下
测试配置文件
/usr/local/bin/nginx/sbin/nginx -t
启动
/usr/local/bin/nginx/sbin/nginx停止
/usr/local/bin/nginx/sbin/nginx -s stop
但是,安装好了,服务器也没有报错,obs软件却没有办法访问?不知道为何。
centos
centos8.2需要安装以下依赖:
yum -y install gcc gcc-c++ kernel-devel
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
另外,vps里面没有gcc、make工具,使用以下进行安装
yum -y install gcc make
操作
obs下载地址 华军
https://www.onlinedown.net/soft/637537.htm
小插曲:
但是安装好obs,配置好nginx服务器,但是无法推流。如果关闭服务,需要2~3秒才响应无法连接服务器,但是如何开启,立马提示,无法连接。可能还是设置哪个环境出错了。以后再研究。
解决方式:共享自己的WiFi,然后可以使用。原来公司网络屏蔽。