# SOCAR AI System - Production Nginx Configuration with SSL/TLS # This configuration provides SSL termination and reverse proxy for production upstream socar_backend { server socar-ai-system:8000; keepalive 32; } # Redirect HTTP to HTTPS server { listen 80; listen [::]:80; server_name _; # ACME challenge location for Let's Encrypt/certbot location /.well-known/acme-challenge/ { root /var/www/certbot; } # Redirect all other traffic to HTTPS location / { return 301 https://$host$request_uri; } } # HTTPS server block server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name _; # SSL Certificate Configuration # For production: Use Let's Encrypt or your CA certificates ssl_certificate /etc/nginx/ssl/fullchain.pem; ssl_certificate_key /etc/nginx/ssl/privkey.pem; # SSL Configuration - Modern settings for security ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; # SSL Session settings ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_session_tickets off; # OCSP Stapling ssl_stapling on; ssl_stapling_verify on; resolver 8.8.8.8 8.8.4.4 valid=300s; resolver_timeout 5s; # Security Headers add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https:;" always; # Logging access_log /var/log/nginx/socar_access.log; error_log /var/log/nginx/socar_error.log; # Client settings client_max_body_size 100M; client_body_buffer_size 10M; # Proxy settings for API location / { proxy_pass http://socar_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_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port; proxy_cache_bypass $http_upgrade; # Timeouts for long-running LLM requests proxy_connect_timeout 60s; proxy_send_timeout 120s; proxy_read_timeout 120s; } # Static files with caching location /static/ { proxy_pass http://socar_backend; proxy_cache_valid 200 1d; add_header Cache-Control "public, max-age=86400"; } # Health check endpoint (no caching) location /health { proxy_pass http://socar_backend; proxy_cache_bypass 1; add_header Cache-Control "no-cache, no-store, must-revalidate"; } }