1、
下载nginx
http://nginx.org/en/download.html
下载nginx-rtmp-module:
nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module
2、安装nginx
- yum -y install openssl openssl-devel
- cd nginx-1.15.0
- ./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module-master --with-http_ssl_module
- make && make install
3、修改nginx配置文件:加入下面内容
rtmp {
server {
listen 1935; #监听的端口
chunk_size 4000;
application hls { #rtmp推流请求路径
live on;
hls on;
hls_path /usr/share/nginx/html/hls;
hls_fragment 5s;
}
}
}
修改server
server {
listen 8086;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
add_header Cache-Control no-cache;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
add_header 'Access-Control-Allow-Headers' 'Range';
root /usr/share/nginx/html;
index index.html index.htm;
}
hls_path需要可读可写的权限,因为/usr/share/nginx/html/hls在目录中还没有,所以使用以下命令创建目录
mkdir -p /usr/share/nginx/html/hls
sudo chmod -R 777 /usr/share/nginx/html/hls
启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
4、下载obs https://obsproject.com/download
然后设置,文件》设置
填写完,选择应用。然后开始推流。
在/usr/share/nginx/html/hls会生成test.m3u8
5、在手机浏览器访问
ip:8086/hls/test.m3u8