# Nginx configuration for VOD HLS Player (Initial - before SSL)
# Domain: player.protov1.t.midshore.space

# Rate limiting for security
limit_req_zone $binary_remote_addr zone=player_limit:10m rate=10r/s;

# Upstream backend
upstream vod_player_backend {
    server 127.0.0.1:8082;
    keepalive 32;
}

# HTTP server - initially serves everything
server {
    listen 80;
    listen [::]:80;
    server_name player.protov1.t.midshore.space;
    
    # Let's Encrypt challenge
    location /.well-known/acme-challenge/ {
        root /var/www/html;
    }
    
    # Serve application
    location / {
        # Rate limiting
        limit_req zone=player_limit burst=20 nodelay;
        
        # Proxy to Python backend
        proxy_pass http://vod_player_backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        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_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
        
        # Timeouts
        proxy_connect_timeout 30s;
        proxy_send_timeout 30s;
        proxy_read_timeout 30s;
        
        # Buffer settings
        proxy_buffering on;
        proxy_buffer_size 4k;
        proxy_buffers 8 4k;
    }
    
    # Static files caching
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
        proxy_pass http://vod_player_backend;
        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_set_header X-Forwarded-Proto $scheme;
        
        # Cache static files
        expires 1y;
        add_header Cache-Control "public, immutable";
    }
    
    # Logging
    access_log /var/log/nginx/vod-player.access.log;
    error_log /var/log/nginx/vod-player.error.log;
}
