# nginx/conf.d/default.conf -- SSL Termination + Reverse Proxy # Input: HTTPS requests on port 443, HTTP requests on port 80 # Output: Proxied requests to upstream app:8080 with TLS terminated at Nginx # # Replace example.com with your domain name. # Requires valid certificates at /etc/letsencrypt/live/example.com/ # HTTP -> HTTPS redirect + ACME challenge support server { listen 80; listen [::]:80; server_name example.com www.example.com; # Let's Encrypt ACME HTTP-01 challenge handler location /.well-known/acme-challenge/ { root /var/www/certbot; } # Redirect all other HTTP traffic to HTTPS location / { return 301 https://$host$request_uri; } } # HTTPS server with SSL termination and reverse proxy server { listen 443 ssl; listen [::]:443 ssl; http2 on; # Nginx 1.25+ syntax (replaces 'listen 443 ssl http2') server_name example.com www.example.com; # SSL certificates managed by Certbot / Let's Encrypt ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # Modern TLS configuration (A+ on SSL Labs) 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; ssl_prefer_server_ciphers off; # SSL session optimization ssl_session_cache shared:SSL:10m; ssl_session_timeout 1d; ssl_session_tickets off; # OCSP stapling for faster TLS handshakes ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; resolver 1.1.1.1 1.0.0.1 valid=300s; resolver_timeout 5s; # Security headers add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "DENY" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; # Reverse proxy to upstream application location / { proxy_pass http://app:8080; 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_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_read_timeout 90s; proxy_buffering on; } }