# HTTP to HTTPS redirect (run this first without SSL) # After SSL certificates are obtained, use the SSL version below server { listen 80; server_name _; # Accept any server name (change to your domain for production) # Health check endpoint for Docker location /nginx-health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # Proxy all requests to the Next.js app location / { proxy_pass http://app:3000; 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; proxy_read_timeout 86400; } # Static files caching location /_next/static { proxy_pass http://app:3000; proxy_cache_valid 200 365d; add_header Cache-Control "public, immutable"; } # API rate limiting location /api/ { limit_req zone=api burst=20 nodelay; limit_conn addr 10; proxy_pass http://app:3000; 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; } # Auth endpoints - stricter rate limiting location /api/auth/ { limit_req zone=auth burst=5 nodelay; limit_conn addr 5; proxy_pass http://app:3000; proxy_http_version 1.1; 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; } }