美文网首页Linux服务器
LEMP服务器搭建一(直播搭建配置)

LEMP服务器搭建一(直播搭建配置)

作者: 心无执着 | 来源:发表于2017-04-18 10:51 被阅读168次

    1.购买一台阿里云服务器,配置centos7.2 64位

    2.安装扩展(#号后表示控制台命令)

    #yum -y install gcc gcc-c++ ncurses-devel perl zlib zlib-devel openssl openssl-devel pcre-devel unzip zip git

    3.下载nginx,rtmp源码

    #wget http://nginx.org/download/nginx-1.9.15.tar.gz

    #wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

    3.解压

    #tar -zxvf nginx-1.9.15.tar.gz

    #unzip master.zip

    4.编译安装nginx

    #cd nginx-1.9.15

    #./configure--with-http_ssl_module--add-module=../nginx-rtmp-module-master

    #make

    #make install

    5.测试nginx

    启动nginx

    #/usr/local/nginx/sbin/nginx

    浏览器访问你的IP地址,如果出现nginx欢迎界面,安装成功

    6.配置rtmp模块

    #vi /usr/local/nginx/conf/nginx.conf

    6.1配置主播推流端口,代码在图下面

    rtmp {

    server {

    listen 1935;

    chunk_size 4096;

    application live {

    live on;

    record off;

    hls on;

    #on_publish http://127.0.0.1/auth_client.php;

    hls_path /tmp/hls;

    hls_fragment 2s;

    }

    }

    }

    6.2配置观众观看端口,代码在图下面


    直接把以下代码复制到配置中,跟server同级-----START


    upstream hls {

    server 127.0.0.1:8080;

    }

    server {

    listen 8080;

    location /stat {

    rtmp_stat all;

    rtmp_stat_stylesheet stat.xsl;

    }

    location /stat.xsl {

    root /root/nginx-rtmp-module-master/stat.xsl/;

    }

    location /hls {

    # Serve HLS fragments

    types {

    application/vnd.apple.mpegurl m3u8;

    video/mp2t ts;

    }

    root /tmp;

    add_header Cache-Control no-cache;

    }

    location /dash {

    # Serve DASH fragments

    root /tmp;

    add_header Cache-Control no-cache;

    }

    location /control {

    rtmp_control all;

    }

    error_page 500 502 503 504 /50x.html;

    location = /50.html {

    root html;

    }

    }


    直接把以上代码复制到配置中,跟server同级-----END


    #以下代码配置在80端口,为反向代理到hls,

    location /hls {#这个hls是访问url中的http://IP/hls/XXX

    proxy_pass http://hls;#这个hls是与upstream中一样的,与url中hls无关,可以与url中不一样

    }

    6.3配置好后重启nginx

    6.3.1关闭后重启

    #/usr/local/nginx/sbin/nginx -s stop

    #/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

    6.3.2直接重启

    #/usr/local/nginx/sbin/nginx -s reload

    7.测试直播

    7.1主播推流

    推荐用OBS,推流地址rtmp://IP:1935/live

    串流码随便填,用户观看哪个主播的地址后缀,假设为live

    7.2用户观看地址

    浏览器访问http://IP/hls/live.m3u8

    如果没有反向代理8080端口到hls,则地址是http://IP:8080/hls/live.m3u8


    至次,直播搭建完成,接下来将会讲如何在此基础上搭建PHP模块,并监听主播的推流。下一标题《LEMP服务器搭建二(PHP,MYSQL配置)》。

    转载请注明原作者及网址

    直接把一下代码复制到配置中,跟server同级-----START

    相关文章

      网友评论

        本文标题:LEMP服务器搭建一(直播搭建配置)

        本文链接:https://www.haomeiwen.com/subject/ggtfzttx.html