# Increase buffer limits to prevent "400 Bad Request - Request Header Or Cookie Too Large"
# These must be in the http context (outside the server block) to be applied during initial request parsing
large_client_header_buffers 4 64k;
client_header_buffer_size 16k;

server {
    listen 80;
    server_name localhost;

    # Increase upload limits for maps or databases if needed
    client_max_body_size 64M;

    # Next.js Application
    location /sistem-km-next {
        proxy_pass http://next-app:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        
        # Standard proxy headers
        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;

        # Disable buffering for hot module reloading (HMR) / Server Sent Events (SSE)
        proxy_buffering off;
    }

    # PHP + Static Web GIS application
    location / {
        proxy_pass http://php-app:80;
        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;
    }
}
