课堂笔记day42

#!/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<<EOF     

#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<<EOF

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>PC HLS video</title>

    <link href="http://cdn.bootcss.com/video.js/6.0.0-RC.5/alt/video-js-cdn.min.css" rel="stylesheet">

</head>

<body>

<h1>PC 端播放 HLS(<code>.m3u8</code>) 视频</h1>

<p>借助 video.js 和 videojs-contrib-hls</p>

<p>由于 videojs-contrib-hls 需要通过 XHR 来获取解析 m3u8 文件, 因此会遭遇跨域问题, 请设置浏览器运行跨域</p>

<video id="hls-video" width="300" height="200" class="video-js vjs-default-skin"

      playsinline webkit-playsinline

      autoplay controls preload="auto"

      x-webkit-airplay="true" x5-video-player-fullscreen="true" x5-video-player-typ="h5">

    <!-- 直播的视频源 -->

    <source src="http://ivi.bupt.edu.cn/hls/cctv13.m3u8" type="application/x-mpegURL">

    <!-- 点播的视频源 -->

    <!--<source src="http://devstreaming.apple.com/videos/wwdc/2015/413eflf3lrh1tyo/413/hls_vod_mvp.m3u8" type="application/x-mpegURL">-->

</video>

<script src="http://cdn.bootcss.com/video.js/6.0.0-RC.5/video.js"></script>

<!-- PC 端浏览器不支持播放 hls 文件(m3u8), 需要 videojs-contrib-hls 来给我们解码 -->

<script src="http://cdn.bootcss.com/videojs-contrib-hls/5.3.3/videojs-contrib-hls.js"></script>

<script>

    // 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();

</script>

</body>

</html>

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容