1.运行环境
Ubuntu 20.04
2.默认路径
/home/abc/workspace
3.下载nginx-rtmp-module
cd /home/abc/workspace
git clone https://github.com/arut/nginx-rtmp-module.git
4.nginx编译安装
下载nginx-1.12.0.tar.gz
wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/home/abc/workspace/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module
make && make install
编译可能遇到问题1.缺少pcre
sudo apt-get install libpcre3 libpcre3-dev
2.缺少opensslsudo apt-get install openssl libssl-dev
3.缺少zlibsudo apt-get install zlib1g-dev
4.this statement may fall through [-Werror=implicit-fallthrough=]警告都被当作是错误
cd /home/abc/workspace/nginx-1.12.0/objs
vim Makefile
删除CFLAGS中的-Werror,保存
5.struct crypt_data’ has no member named ‘current_salt’cd /home/abc/workspace/nginx-1.12.0/src/os/unix/
vim ngx_user.c
注释报错的行
5.验证Nginx运行
cd /home/abc/workspace/nginx/sbin
sudo ./nginx
在Ubuntu的浏览器中输入localhost,如果有Welcome页,则本地运行正常,另外在Windows的浏览器中输入虚拟机ip,如果也出现Welcome页,则表明通信也正常
6.修改配置文件
cd /home/abc/workspace/nginx/conf
vim nginx.conf
......
events {
worker_connections 1024;
}
//添加下面一段
rtmp {
server {
listen 1935;
chunk_size 4096;
application vod {
play /opt/video/vod;
}
application live{ #第一处添加的直播字段
live on;
hls on;
hls_path /home/abc/workspace/nginx/html/ts;
hls_fragment 5s;
}
}
}
......
重启服务
cd /home/abc/workspace/nginx/sbin
sudo ./nginx -s reload
7.推流+拉流
推流使用OBS
设置推流地址rtmp://192.168.163.128:1935/live
vlc拉流
打开网络串流,输入地址rtmp://192.168.163.128:1935/live
替换成自己服务器的IP地址