编译好之后,就是启动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
9月 16 16:43:51 hui gnome-shell[7841]: [AppIndicatorSupport-WARN] Attempting to re-register :1.2/StatusNotifierItem; resetting instead
9月 16 16:43:51 hui gnome-shell[7841]: [AppIndicatorSupport-WARN] Item :1.2/StatusNotifierItem is already registered
9月 16 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