一、安装一下软件依赖
[root@tecent ~]# yum install readline-devel pcre-devel openssl-devel -y
[root@tecent ~]# yum install wget perl gcc unzip -y
二、安装包文件
[root@tecent ~]# wget https://openresty.org/download/openresty-1.11.2.4.tar.gz
[root@tecent ~]# tar -xvf openresty-1.11.2.4.tar.gz
[root@tecent ~]# mv openresty-1.11.2.4 openresty
[root@tecent ~]# cd openresty
[root@tecent ~]# ./configure
[root@tecent ~]# make && make install
[root@tecent ~]# ln -s /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx
[root@tecent ~]# cd /home
[root@tecent ~]# wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
[root@tecent ~]# unzip master.zip
[root@tecent ~]# cd openresty
[root@tecent ~]# ./configure --add-module=/home/nginx-rtmp-module-master
[root@tecent ~]# make
[root@tecent ~]# cp /root/openresty/build/nginx-1.11.2/objs/nginx /usr/local/openresty/nginx/sbin
三、配置
配置文件 /usr/local/openresty/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;# 选择epoll模型可以达到最佳的IO性能
worker_connections 1024;
}
rtmp { #RTMP服务
server {
listen 1935; #//服务端口
chunk_size 4096; #//数据传输块的大小
application vod {
play /opt/video; #//视频文件存放位置。
}
application live{ #直播
live on;
hls on; #这个参数把直播服务器改造成实时回放服务器。
wait_key on; #对视频切片进行保护,这样就不会产生马赛克了。
hls_path /opt/video/hls; #切片视频文件存放位置。
hls_fragment 6s; #设置HLS片段长度。
#hls_playlist_length 10m; #设置HLS播放列表长度,这里设置的是10分钟。
hls_playlist_length 60s;
hls_continuous on; #连续模式。
hls_cleanup on; #对多余的切片进行删除。
hls_nested on; #嵌套模式。
#allow publish 127.0.0.1;
#deny publish all;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.qidimangu.club;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /home/nginx-rtmp-module-master/;
}
charset utf-8;
#charset koi8-r;
#access_log logs/host.access.log main;
location /live { #这里也是需要添加的字段。
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
alias /opt/video/hls;
expires -1;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
location /rtmp-publisher {
root /home/nginx-rtmp-module-master/test;
}
location / {
root /home/nginx-rtmp-module-master/test/www;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
测试:
[root@tecent ~]# nginx -t #检查配置文件
[root@tecent ~]# nginx #启动服务
上传一个视频文件test.mp4至/opt/video目录
用VLC软件 rtmp://ip:port/vod/test.mp4点击播放进行测试;另一种要是想通过浏览器进行观看的话配置player.html文件的参数,观看地址:http://域名/rmtp-publisher/player.html
其它的配置说明参考我昨天写的这篇博客:https://blog.csdn.net/Student_xx/article/details/104373747