下载:
wget https:
git clone https:
编译
cd nginx- 1.24 . 0
. / configure -- prefix= / usr/ local/ nginx -- with- http_ssl_module -- add- module = / usr/ local/ nginx/ nginx- http- flv- module
sudo make
sudo make install
配置nginx.conf
rtmp_auto_push on;
rtmp_auto_push_reconnect 1 s;
rtmp {
server {
listen 1935 so_keepalive= 2 s: 1 : 1 ; #监听的端口号
chunk_size 8192 ; # 单一推流数据包的最大容量
application huayu { # 创建rtmp应用hls
live on; # 当路径匹配时,开始播放
# HLS协议进行m3u8实时直播. 如果是http- flv不需要配置下面的
wait_key on; #保护TS切片
hls on; #实时回访
hls_nested on; #每个流都自动创建一个文件夹
hls_path / tmp/ hls; #媒体块ts的位置
hls_fragment 5 s; #每个ts文件为5 s的样子
hls_playlist_length 30 s; #保存m3u8列表长度时间,默认是30 秒,可考虑三小时10800 秒
hls_cleanup on; #是否删除列表中已经没有的媒体块TS文件,默认是开启
hls_continuous on; #连续模式
}
}
}
http {
include mime. types;
default_type application/ octet- stream;
sendfile on;
keepalive_timeout 65 ;
server {
listen 8080 ;
server_name localhost;
location / huayu { # 拉http- flv的配置
flv_live on;
}
location / flv {
add_header 'Access-Control-Allow-Origin' '*' ;
flv_live on;
chunked_transfer_encoding on;
}
location / stat {
rtmp_stat all;
rtmp_stat_stylesheet stat. xsl;
}
location / stat. xsl {
root nginx- http- flv- module / ;
}
location / {
root html;
index index. html index. htm;
}
error_page 500 502 503 504 / 50 x. html;
location = / 50 x. html {
root html;
}
}
server {
listen 8081 ;
server_name localhost;
location ^ ~ / api{
proxy_set_header Host $host;
proxy_set_header X- Real- IP $remote_addr;
proxy_set_header X- Forwarded- For $proxy_add_x_forwarded_for;
proxy_pass http:
# 开启WebSocket代理
# proxy _http_version 1.1 ;
# proxy _set_header Upgrade $http_upgrade;
# proxy _set_header Connection "upgrade" ;
# 配置WebSocket代理,将请求发送到ws:
# proxy _pass http:
# rewrite "^/prod-api/(.*)$" / $1 break ;
}
error_page 500 502 503 504 / 50 x. html;
location = / 50 x. html {
root html;
}
}
}
开机自启
[ Unit]
Description= nginx service
After= network. target
[ Service]
User= root
Type= forking
ExecStart= / usr/ local/ nginx/ sbin/ nginx
ExecReload= / usr/ local/ nginx/ sbin/ nginx - s reload
ExecStop= / usr/ local/ nginx/ sbin/ nginx - s stop
ExecStartPre= / bin/ sleep 10
[ Install]
WantedBy= multi- user. target