NGINX+RTMP搭建流媒体服务
一、 基于docker搭建流服务器
1、 启动rtmp docker容器wangzuoli/nginx-rtmp
docker pull wangzuoli/nginx-rtmp
2、 ##docker run -d -p 1935:1935 -p 8080:80 wangzuoli/nginx-rtmp
3、 打开obs软件进行媒体源添加及设置推流地址
推流地址 rtmp://ip地址:1935/stream
拉流地址:rtmp://IP地址:1935/stream/123
二、 基于物理机搭建流服务器
a,下载安装包
1、 下载nginx-rtmp模块
https://codeload.github.com/arut/nginx-rtmp-module/zip/master
2、 nginx安装包
http://nginx.org/en/download.html
b,编译安装nginx
1、 安装编译器、依赖包
##sudo apt-get install build-essential libssl-dev openssl -y
如没有pcre库,需要yum安装或者编译安装
2、解压trmp模块:
##unzip nginx-rtmp-module-master.zip(安装unzip)
安装nginx:
##tar xvf nginx-1.16.1.tar.gz
##cd nginx-1.16.1
./configure --prefix=/usr/local/nginx \
--add-module=/root/rtmp/nginx-rtmp-module-master \
--with -http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module
## make && make install
c,配置nginx.conf文件
rtmp {
server {
listen 1935;
chunk_size 4000;
application stream {
live on;
}
application hls {
live on;
}
}
}
http {
access_log /dev/stdout combined;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
server {
listen 80;
# Uncomment these lines to enable SSL.
# Update the ssl paths with your own certificate and private key.
# listen 443 ssl;
# ssl_certificate /opt/certs/example.com.crt;
# ssl_certificate_key /opt/certs/example.com.key;
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /opt/data;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location /live {
alias /opt/data/hls;
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet static/stat.xsl;
}
location /static {
alias /www/static;
}
location = /crossdomain.xml {
root /www/static;
default_type text/xml;
expires 24h;
}
}
}
然后start nginx
/usr/local/nginx/sbin/nginx
d,测试推流拉流
重复标题一的第三步