ubuntu配置ngix rtmp点播服务器

编译好之后,就是启动nginx了,sudo service start nginx启动的nginx不是自己编译的。

需要启动/usr/local/nginx/sbin/nginx,编译默认安装在这个目录下:

cd /usr/local/nginx
sudo ./sbin/nginx
sudo vi conf/nginx.conf

/usr/local/nginx/conf/nginx.conf文件内容

worker_processes  1;

events {
    worker_connections  1024;
}

rtmp {
    server { 
        listen 1935;
	    chunk_size 4096;
        
        # rtmp点播
	    application vod {
		    play /opt/video/vod;
	    }

        # rtmp直播
	    application live{ 
		    live on;
	    }
    }
}

http {
    include            mime.types;
    default_type       application/octet-stream;
    sendfile           on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

	    location /stat {
            rtmp_stat all;
	        rtmp_stat_stylesheet stat.xsl;
	    }

	    location /stat.xsl {
		    root nginx-rtmp-module;
	    }

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

stat的说明

location /stat {
    rtmp_stat all;
    rtmp_stat_stylesheet stat.xsl;
}

location /stat.xsl {
    root nginx-rtmp-module;
}
  • 添加stat.xsl,通过浏览器可以看到rtmp的status
  • 添加后http://localhost/stat可以查看,如果放在8080端口段,就是http://localhost:8080/stat
  • stat.xsl文件从nginx-rtmp-module代码目录下copy到/usr/local/nginx/nginx-rtmp-module
  • nginx-rtmp-module写的是相对于/usr/local/nginx下的相对路径也可以。

浏览器里面查看stat
输入localhost/stat,就可以看到熟悉的页面,截图

然后执行nginx reload

sudo ./sbin/nginx -s reload

或者

sudo killall nginx
sudo ./sbin/nginx -c etc/nginx.conf

通过vlc或者ffplay都可以播放

vlc rtmp://localhost/vod/panda.mp4
ffplay rtmp://localhost/vod/panda.mp4

journalctl可以查看nginx运行的日志

$ journalctl -u nginx

916 16:43:51 hui gnome-shell[7841]: [AppIndicatorSupport-WARN] Attempting to re-register :1.2/StatusNotifierItem; resetting instead
916 16:43:51 hui gnome-shell[7841]: [AppIndicatorSupport-WARN] Item :1.2/StatusNotifierItem is already registered
916 16:43:54 hui sudo[30907]:      hui : TTY=pts/11 ; PWD=/home/hui/disk4t/codes/nginx/nginx-1.18.0 ; USER=root ; COMMAND=/usr/bin/vi /etc/nginx/nginx.conf

nginx -t测试说明 nginx 配置是正确的,同时也可以发现load的nginx.conf文件对不对

$ sudo ./sbin/nginx -c etc/nginx.conf -t
nginx: the configuration file /usr/local/nginx/etc/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/etc/nginx.conf test is successful

如果没有用-c指定etc/nginx.conf,load的conf文件是conf/nginx.conf,不是etc/nginx.conf,用了-c和不用-c是有区别的,修改conf文件最好修改conf/nginx.conf,这样不会有修改了不生效的问题。

$ sudo ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


参考

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值