linux nginx-rtmp搭建方法

  • 解压与安装

    报错可以对照第三部分进行查错,命令中的部分目录请以实际解压与安装目录为准。

将nginx、openssl、pcre、zlib、nginx-rtmp-module压缩包放到虚拟机想安装的目录下面。

将压缩包全部解压,解压命令示例:tar -zxvf nginx-1.9.3.tar.gz

依次解压之后进入nginx解压目录下输入

./configure --prefix=/home/htz/nginx-1.9.3 --with-openssl=/home/htz/openssl-1.0.2 --with-pcre=/home/htz/pcre-8.37 --with-zlib=/home/htz/zlib-1.2.8 --add-module=/home/htz/nginx-rtmp-module --with-http_ssl_module

等号后边指定的是对应解压目录。如果不出现错误的话,依次进行make和make install命令,即可完成安装。

二、配置nginx

vi /home/htz/nginx-1.9.3/conf/nginx.conf

加入以下内容:

rtmp {

    server {

        listen 1935;  #监听的端口,推流目标端口

        chunk_size 4096;   

        application hls {  #rtmp推流请求路径  

            live on;    

            hls on;    

            hls_path /home/htz/nginx-1.9.3/html/hls;//根据实际情况确定路径    

            hls_fragment 5s;    

        }    

    }    

}  

修改http中的server模块:

server {  

    listen       81;  

    server_name  localhost;  

  

    #charset koi8-r;  

  

    #access_log  logs/host.access.log  main;  

  

    location / {  

        root   html;  

        index  index.html index.htm;  

    }  

    location /stat{

            rtmp_stat all;

            rtmp_stat_stylesheet stat.xsl;

        }

        location /stat.xsl{

            root html;//nginx-rtmo-module下有此文件

        }

 

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

    }  

然后启动nginx:

/home/htz/nginx-1.9.3/sbin/nginx -c /home/htz/nginx-1.9.3/conf/nginx.conf

浏览器输入localhost:81即可显示出成功界面

检查配置文件是否出错命令

/home/htz/nginx-1.9.3/sbin/nginx -t

重启nginx命令

/home/htz/nginx-1.9.3/sbin/nginx -s reload

三、可能出现错误

1.install Error

解决方法

出现错误1的情况下,将命令改为./configure --prefix=/home/htz/nginx-1.9.3 --conf-path=/home/htz/nginx-1.9.3/nginx.conf --with-openssl=/home/htz/openssl-1.0.2q --with-pcre=/home/htz/pcre-8.35 --with-zlib=/home/htz/zlib-1.2.11 --add-module=/home/htz/nginx-rtmp-module-master --with-http_ssl_module

若安装路径不是nginx-1.9.3的解压目录,则不会出现错误1

在命令后,指定path

2.localhost:81显示nginx 404 not found

解决方法:

可能是权限问题,在nginx目录下conf/nginx.conf的配置文件中头行加入 user root;

3.localhost:81显示403 forbidden

解决方法:

可能时配置文件中server-location-root中文件夹中没有index.html文件,可以指定默认文件夹,或者自己添加文件夹

4.端口被占用

一切错误

解决方法:

netstat -ntlp查看端口占用情况

kill -9 pid号 杀死占用端口进程,如:

kill -9 20063

 

5.修改错误或者配置文件后,一定不要忘记重启。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值