108 lines
3 KiB
Text
108 lines
3 KiB
Text
# Upstream backend service
|
|
upstream backend {
|
|
server backend:8000;
|
|
keepalive 32;
|
|
}
|
|
|
|
# HTTP server - redirect to HTTPS
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name getmaplepress.ca www.getmaplepress.ca;
|
|
|
|
# Let's Encrypt challenge location
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/certbot;
|
|
}
|
|
|
|
# Health check endpoint (for load balancer)
|
|
location /health {
|
|
access_log off;
|
|
return 200 "healthy\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# Redirect all other HTTP traffic to HTTPS
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
# HTTPS server
|
|
server {
|
|
listen 443 ssl http2;
|
|
listen [::]:443 ssl http2;
|
|
server_name getmaplepress.ca www.getmaplepress.ca;
|
|
|
|
# SSL certificates (Let's Encrypt)
|
|
ssl_certificate /etc/letsencrypt/live/getmaplepress.ca/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/getmaplepress.ca/privkey.pem;
|
|
|
|
# SSL configuration (Mozilla Intermediate)
|
|
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;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
ssl_stapling on;
|
|
ssl_stapling_verify on;
|
|
|
|
# Security headers
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" 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;
|
|
|
|
# Logging
|
|
access_log /var/log/nginx/access.log main;
|
|
error_log /var/log/nginx/error.log warn;
|
|
|
|
# Proxy settings
|
|
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;
|
|
|
|
# Timeouts
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# Buffer settings
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
proxy_busy_buffers_size 8k;
|
|
|
|
# API endpoints (rate limited)
|
|
location /api/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
proxy_pass http://backend;
|
|
}
|
|
|
|
# All other requests
|
|
location / {
|
|
limit_req zone=general burst=5 nodelay;
|
|
proxy_pass http://backend;
|
|
}
|
|
|
|
# Health check (internal)
|
|
location /health {
|
|
access_log off;
|
|
proxy_pass http://backend/health;
|
|
}
|
|
|
|
# Metrics endpoint (if exposed)
|
|
location /metrics {
|
|
access_log off;
|
|
deny all; # Only allow from monitoring systems
|
|
# allow 10.116.0.0/16; # Uncomment to allow from VPC
|
|
proxy_pass http://backend/metrics;
|
|
}
|
|
}
|