# Nginx Configuration Fixes for Next.js Server Actions and Headers
# Add these to your existing Nginx configuration

# Inside your server block for Next.js, update the location / block:

location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    
    # Essential headers for Next.js
    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;
    
    # CRITICAL: Headers for Next.js Server Actions
    proxy_set_header Origin $scheme://$host;
    proxy_set_header Referer $scheme://$host$request_uri;
    
    # Preserve all request headers
    proxy_pass_request_headers on;
    
    # Cache bypass
    proxy_cache_bypass $http_upgrade;
    
    # Timeouts
    proxy_connect_timeout 60s;
    proxy_send_timeout 60s;
    proxy_read_timeout 60s;
    
    # Buffer settings
    proxy_buffering off;
    proxy_request_buffering off;
}

# Also add this for Next.js Server Actions endpoint
location /_next/static {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_cache_valid 200 60m;
    add_header Cache-Control "public, immutable";
}

