events {
    worker_connections 1024;
}

# RTMP configuration
rtmp {
    server {
        listen 1935; # Listen on standard RTMP port
        chunk_size 4000;

        application live {
            live on;
            
            # Turn on HLS
            hls on;
            hls_path /app/media;
            hls_fragment 3;
            hls_playlist_length 60;
            
            # Disable consuming the stream from nginx as rtmp
            deny play all;
        }
    }
}

# HTTP configuration
http {
    sendfile off;
    tcp_nopush on;
    # aio on;  # Disabled - not supported on all platforms
    # directio 512;
    default_type application/octet-stream;

    server {
        listen 80;

    
        # HLS playlist files
        location ~* \.m3u8$ {
            add_header Content-Type application/vnd.apple.mpegurl;
            add_header Access-Control-Allow-Origin *;
            add_header Cache-Control no-cache;
            root /app/media;
        }
        
        # HLS segment files  
        location ~* \.ts$ {
            add_header Content-Type video/mp2t;
            add_header Access-Control-Allow-Origin *;
            add_header Cache-Control no-cache;
            root /app/media;
        }

        # Fallback for other requests
        location / {
            root /app/media;
        }
    }
}