user www-data;
worker_processes 1;
pid /run/nginx.pid;

include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;

    map $arg_name $rtmp_publish_allowed {
        default 0;
        "HIER_DEINEN_STREAM_KEY_EINTRAGEN" 1;
    }

    server {
        listen 127.0.0.1:8080;
        server_name localhost;

        access_log /var/log/nginx/rtmp-auth-access.log;
        error_log /var/log/nginx/rtmp-auth-error.log;

        location = /publish-auth {
            if ($rtmp_publish_allowed = 0) {
                return 403;
            }
            return 200;
        }
    }

    server {
        listen 8081;
        server_name _;

        access_log /var/log/nginx/rtmp-stat-access.log;
        error_log /var/log/nginx/rtmp-stat-error.log;

        location = / {
            return 302 /stat;
        }

        location = /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
            add_header Cache-Control "no-store" always;
        }

        location = /stat.xml {
            rtmp_stat all;
            add_header Cache-Control "no-store" always;
        }

        location = /stat.xsl {
            root /usr/share/nginx/html;
        }
    }
}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            live on;
            record off;
            notify_method get;
            on_publish http://127.0.0.1:8080/publish-auth;
            allow publish all;
            allow play all;
        }
    }
}
