worker_processes  1; #运行在Windows上时，设置为1，因为Windows不支持Unix domain socket
#worker_processes  auto; #1.3.8和1.2.5以及之后的版本
 
#worker_cpu_affinity  0001 0010 0100 1000; #只能用于FreeBSD和Linux
#worker_cpu_affinity  auto; #1.9.10以及之后的版本
 
error_log logs/error.log error;
 
#如果此模块被编译为动态模块并且要使用与RTMP相关的功
#能时，必须指定下面的配置项并且它必须位于events配置
#项之前，否则NGINX启动时不会加载此模块或者加载失败
 
#load_module modules/ngx_http_flv_live_module.so;
 
events {
    worker_connections  4096;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    keepalive_timeout  65;
 
    server {
        listen       80;
 
        location / {
            root   /var/www;
            index  index.html index.htm;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
        location /live {
            flv_live on; #打开HTTP播放FLV直播流功能
            chunked_transfer_encoding on; #支持'Transfer-Encoding: chunked'方式回复
 
            add_header 'Access-Control-Allow-Origin' '*'; #添加额外的HTTP头
            add_header 'Access-Control-Allow-Credentials' 'true'; #添加额外的HTTP头
        }
 
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
 
            root /tmp;
            add_header 'Cache-Control' 'no-cache';
        }
 
        location /dash {
            root /tmp;
            add_header 'Cache-Control' 'no-cache';
        }
 
        location /stat {
            #push和pull状态的配置
 
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
 
        location /stat.xsl {
            root /var/www/rtmp; #指定stat.xsl的位置
        }
 
        #如果需要JSON风格的stat, 不用指定stat.xsl
        #但是需要指定一个新的配置项rtmp_stat_format
 
        #location /stat {
        #    rtmp_stat all;
        #    rtmp_stat_format json;
        #}
 
        location /control {
            rtmp_control all; #rtmp控制模块的配置
        }
    }
}
 
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
 
rtmp {
    out_queue           4096;
    out_cork            8;
    max_streams         128;
    timeout             15s;
    drop_idle_publisher 15s;
 
    log_interval 5s; #log模块在access.log中记录日志的间隔时间，对调试非常有用
    log_size     1m; #log模块用来记录日志的缓冲区大小
 
    server {
        listen 1935;
        server_name www.test.*; #用于虚拟主机名后缀通配
 
        application myapp {
            live on;
            gop_cache on; #打开GOP缓存，减少首屏等待时间
        }
 
        application hls {
            live on;
            hls on;
            hls_path /tmp/hls;
        }
 
        application dash {
            live on;
            dash on;
            dash_path /tmp/dash;
        }
    }
 
    server {
        listen 1935;
        server_name *.test.com; #用于虚拟主机名前缀通配
 
        application myapp {
            live on;
            gop_cache on; #打开GOP缓存，减少首屏等待时间
        }
    }
 
    server {
        listen 1935;
        server_name www.test.com; #用于虚拟主机名完全匹配
 
        application myapp {
            live on;
            gop_cache on; #打开GOP缓存，减少首屏等待时间
        }
    }
}
