1、下载Nginx源码并解压:
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar -xvf nginx-1.12.1.tar.gz
2、下载nginx-rtmp-module
git clone https://github.com/arut/nginx-rtmp-module.git
3、配置Nginx
在解压好的nginx源码中进行config:
./configure --add-module=/Users/rainmanwang/work/nginx/nginx-rtmp-module
这步也许会因某些库没有安装报错,缺哪个库手动安装之后再重新config即可。
mac上OpenSSL报错的解决办法:
./configure:error:SSL modules require the OpenSSL library.
这是因为mac上自带openssl库,用到ssl的时候就会比较敏感,linux机器不会有这个问题,这里只需将ssl库的路径export出来在重新config即可:
export CPATH=/usr/local/opt/openssl/include
export LIBRARY_PATH=/usr/local/opt/openssl/lib
4、make && make install
默认安装路径是/usr/local/nginx
5、配置nginx服务器:
在/usr/local/nginx/conf/nginx.conf中添加如下配置项:
rtmp {
server {
listen 1935;
chunk_size 4096;
application rainman_live {
live on;
}
}
}
6、运行nginx服务器
./usr/local/nginx/sbin/nginx
ps -ef | grep nginx 可见已成功运行
使用ffmpeg推流,VCL拉流测试:
ffmpeg 推流命令:
ffmpeg -re -i ./v1080.mp4 -vcodec libx264 -acodec aac -f flv rtmp://10.43.99.125/rainman_live
VLC拉流:
至此已经可以正常推流并拉流播放,nginx还可以配置一些插件来监测推流状态:
同样在/usr/local/nginx/conf/nginx.conf中添加如下配置项:
server {
listen 8080;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /Users/rainmanwang/work/nginx/nginx-rtmp-module;
}
}
pkill nginx并重新运行nginx在推流
打开http://10.43.99.125:8080/stat就可以实时监测推流信息啦: