upstream backend { server bot:3000; keepalive 32; } # HTTP to HTTPS redirect server { listen 80; server_name _; # Health check endpoint location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # Redirect all HTTP traffic to HTTPS location / { return 301 https://$host$request_uri; } } # Main server block server { listen 443 ssl http2; server_name your-domain.com www.your-domain.com; # SSL configuration (uncomment and configure for production) # ssl_certificate /etc/nginx/ssl/cert.pem; # ssl_certificate_key /etc/nginx/ssl/key.pem; # ssl_session_timeout 1d; # ssl_session_cache shared:SSL:50m; # ssl_session_tickets off; # ssl_protocols TLSv1.2 TLSv1.3; # ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384; # ssl_prefer_server_ciphers off; # Security headers add_header Strict-Transport-Security "max-age=63072000" always; # Increase max body size for uploads client_max_body_size 10M; # API endpoints with rate limiting location /api/ { limit_req zone=api burst=20 nodelay; proxy_pass http://backend; 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; # Timeouts proxy_connect_timeout 5s; proxy_send_timeout 60s; proxy_read_timeout 60s; } # OAuth callback with stricter rate limiting location /api/auth/ { limit_req zone=login burst=5 nodelay; proxy_pass http://backend; 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; } # Static files (React app) location / { proxy_pass http://backend; 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; # Cache static assets location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { proxy_pass http://backend; expires 1y; add_header Cache-Control "public, immutable"; } } # Health check location /health { access_log off; proxy_pass http://backend/api/health; } } # Development server block (uncomment for development with SSL) # server { # listen 443 ssl http2; # server_name localhost; # # # Self-signed certificate for development # ssl_certificate /etc/nginx/ssl/localhost.crt; # ssl_certificate_key /etc/nginx/ssl/localhost.key; # # location / { # proxy_pass http://backend; # 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; # } # }