1、下载nginx:
nginx的官方网站为:nginx: download
解压:
tar xvf nginx-1.10.3.tar.gz
2、安装nginx依赖运行包命令:
sudo apt-get install libssl-dev
sudo apt-get install libpcre3 libpcre3-dev
3、下载nginx-rtmp-module:
nginx-rtmp-module的官方github地址:
GitHub - arut/nginx-rtmp-module: NGINX-based Media Streaming Server
使用命令:
git clone https://github.com/arut/nginx-rtmp-module.git
解压:
unzip nginx-rtmp-module-master.zip
mv -i nginx-rtmp-module-master nginx-rtmp-module
4、编译安装:
./configure --add-module=../nginx-rtmp-module
make && make install
5、修改nginx的配置文件
vi /usr/local/nginx/conf/nginx.conf
加入以下内容:
rtmp{
server{
listen 1935;
chunk_size 4000;
application hls {
live on;
hls on;
hls_path /home/rtmp/hls;
hls_fragment 2s;
hls_playlist_length 6s;
}
}
}
hls_path需要可读可写的权限。
修改http中的server模块:
server {
listen 80;
server_name localhost;
location /hls {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
types {
application/vnd.apple.mpegusr m3u8;
video/mp2t ts;
}
root /home/rtmp;
add_header Cache-Control no-cache;
}
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
if ($request_filename ~* ^.*?\.(txt|doc|pdf|tar|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
add_header Content-Disposition: 'attachment;';
}
autoindex on;#打开目录浏览功能
autoindex_exact_size off;#改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
autoindex_localtime on;#显示的文件时间为文件的服务器时间
}
#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;
}
}
6、测试nginx-rtmp服务
推流:
ffmpeg -re -i "264_aac.mp4" -vcodec libx264 -s 480x270 -vprofile baseline -acodec copy -f flv rtmp://192.168.1.190:1935/hls/test
拉流:
rtmp:/192.168.1.190:1935/hls/test
http://192.168.1.190:80/hls/test.m3u8