#user nobody;
user www www;
worker_processes 8;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
#rtmp 配置
rtmp {
server {
listen 1935; #監聽的端口號
chunk_size 4096; #數據傳輸塊的大小
application experienceApp { #rtmp推流請求路徑
live on;
drop_idle_publisher 5s; #5s時間內丟棄空閑的publisher
}
application hls { #rtmp推流請求路徑
live on;
hls on;
drop_idle_publisher 5s; #5s時間內丟棄空閑的publisher
wait_key on; #使視頻流開始一個關鍵幀。默認為關閉。
hls_path /tmp/hls; #視頻存放地址
hls_fragment 10s; #每個視頻切片的時長。
hls_playlist_length 60s; #總共可以回看的事件,這里設置的是1分鍾。
hls_continuous on; #連續模式。
hls_cleanup on; #對多余的切片進行刪除。
hls_nested on; #打開后的作用是每條流自己有一個文件夾
}
}
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server_tokens off;
# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen 80;
add_header Access-Control-Allow-Origin *;
#HLS配置開始,這個配置為了客戶端能夠以http協議獲取HLS的拉流
location /hls {
add_header Access-Control-Allow-Origin *;
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp; #跟上面的hls_path路徑對應
expires -1;
#防止跨域問題
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/nginx/modules/nginx-rtmp-module-master/;
}
location / {
root html;
index index.html index.htm;
}
}
# 引入域名的配置
include vhosts/*.conf;
}