events { worker_connections 1024; }

http {
    upstream chrome_servers {
        # ip_hash ensures a user stays on the same container
        # ip_hash; 
        
        server chrome:6901;
    }

    server {
        listen 80;

        location / {
            # Change 'http' to 'https'
            proxy_pass https://chrome_servers; 
        
            # Tell Nginx it's okay to use self-signed certs for internal traffic
            proxy_ssl_verify off;
            proxy_ssl_server_name on;
            
            # Critical for VNC/Websocket stability
            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;

            # Increase timeouts so the session doesn't drop during inactivity
            proxy_read_timeout 86400s;
            proxy_send_timeout 86400s;
        }
    }
}
