#!/bin/sh
cd /etc/yum.repos.d #
mv CentOS-Base.repo ./CentOS-Base.repo.backup #移动(规范)
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo #换源 安装东西就到它这下面找
yum makecache #安装makecache(同步服务器上的缓存)这个包
yum update -y #更新升级
yum install git gcc make pcre-devel openssl-devel #安装git gcc make pcre-devel openssl-devel这些包
cd /usr/local/ #到时local下
git clone git://github.com/arut/nginx-rtmp-module.git #扩展包
wget http://nginx.org/download/nginx-1.15.0.tar.gz #安装nginx源码压缩包
tar xzf nginx-1.15.0.tar.gz #解压源码包
cd nginx-1.15.0
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module #编译文件
make && make install #创建并安装它建立makefile文件
cd ../nginx/sbin/
./nginx -V #查看版本号
./nginx
./nginx #第二次查看启动没
systemctl stop firewalld.service # 关防火墙
firewall-cmd --state # 查看防火墙状态not running
#修改Nginx的conf文件 配置rtmp端口 1935端口
cat >/usr/local/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 { worker_connections 1024; } rtmp{ server{ listen 1935; chunk_size 5000; application hls{ live on; hls on; record off; hls_path /usr/local/nginx/html/hls; hls_fragment 3s; } } } http { include mime.types; default_type application/octet-stream; #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 localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /hls { #server hls fragments types{ application/vnd.apple.mpegurl m3u8; video/mp2t ts; } alias /temp/hls; expires -1; } #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; # } #} } EOF #增加 cat >/usr/local/nginx/html/play.html<
PC 端播放 HLS(.m3u8
) 视频
借助 video.js 和 videojs-contrib-hls
由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域
// XMLHttpRequest cannot load http://xxx/video.m3u8. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.198.98:8000' is therefore not allowed access.
// 由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域
var player = videojs('hls-video');
player.play();
EOF
cd /usr/local/nginx/conf
/usr/local/nginx/sbin/nginx -s stop #停止服务
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #启动服务
/usr/local/nginx/sbin/nginx #查看是否城功
#OBS推流机 rtmp://主机ip地址:1935/oldboy_live room01 room02
#google浏览器上 输 自己IP/play.html