worker_processes 1;

events {
    worker_connections 1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent"';

    access_log /var/log/nginx/access.log main;
    error_log /var/log/nginx/error.log debug;

    sendfile on;
    keepalive_timeout 65;

    upstream gunicorn {
        server gunicorn:8000;
    }

    server {
        listen 8080;
        server_name localhost;

        # Increase buffer sizes for large headers
        uwsgi_buffer_size 32k;
        uwsgi_buffers 8 32k;
        uwsgi_busy_buffers_size 64k;

        # Read timeout for large responses
        uwsgi_read_timeout 300s;

        location / {
            uwsgi_pass gunicorn;
            include uwsgi_params;

            # Pass additional headers
            uwsgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for;
            uwsgi_param HTTP_X_REAL_IP $remote_addr;
        }
    }
}
