115 lines
3.5 KiB
Nginx Configuration File
115 lines
3.5 KiB
Nginx Configuration File
|
|
user nginx;
|
||
|
|
worker_processes auto;
|
||
|
|
|
||
|
|
error_log /var/log/nginx/error.log warn;
|
||
|
|
pid /var/run/nginx.pid;
|
||
|
|
|
||
|
|
events {
|
||
|
|
worker_connections 1024;
|
||
|
|
}
|
||
|
|
|
||
|
|
http {
|
||
|
|
include /etc/nginx/mime.types;
|
||
|
|
default_type application/octet-stream;
|
||
|
|
|
||
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||
|
|
'$status $body_bytes_sent "$http_referer" '
|
||
|
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
||
|
|
|
||
|
|
access_log /var/log/nginx/access.log main;
|
||
|
|
|
||
|
|
sendfile on;
|
||
|
|
keepalive_timeout 65;
|
||
|
|
|
||
|
|
# Security headers
|
||
|
|
map $http_upgrade $connection_upgrade {
|
||
|
|
default upgrade;
|
||
|
|
'' close;
|
||
|
|
}
|
||
|
|
|
||
|
|
# HTTP server: serve ACME challenge and redirect everything else to HTTPS
|
||
|
|
server {
|
||
|
|
listen 80;
|
||
|
|
server_name _;
|
||
|
|
|
||
|
|
# ACME challenge
|
||
|
|
location ^~ /.well-known/acme-challenge/ {
|
||
|
|
root /var/www/certbot;
|
||
|
|
}
|
||
|
|
|
||
|
|
location / {
|
||
|
|
return 301 https://$host$request_uri;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# HTTPS server
|
||
|
|
server {
|
||
|
|
listen 443 ssl http2;
|
||
|
|
server_name _;
|
||
|
|
|
||
|
|
# TLS certs (managed by certbot). We use fixed cert-name 'portal'
|
||
|
|
ssl_certificate /etc/letsencrypt/live/portal/fullchain.pem;
|
||
|
|
ssl_certificate_key /etc/letsencrypt/live/portal/privkey.pem;
|
||
|
|
ssl_session_timeout 1d;
|
||
|
|
ssl_session_cache shared:SSL:10m;
|
||
|
|
ssl_session_tickets off;
|
||
|
|
|
||
|
|
# Modern TLS config
|
||
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||
|
|
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256';
|
||
|
|
ssl_prefer_server_ciphers off;
|
||
|
|
|
||
|
|
# Security headers
|
||
|
|
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
|
||
|
|
add_header X-Frame-Options DENY;
|
||
|
|
add_header X-Content-Type-Options nosniff;
|
||
|
|
add_header Referrer-Policy no-referrer-when-downgrade;
|
||
|
|
add_header Permissions-Policy "geolocation=(), microphone=(), camera=(), payment=(), usb=(), vr=()";
|
||
|
|
add_header Content-Security-Policy "default-src 'self'; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; script-src 'self'; font-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'" always;
|
||
|
|
|
||
|
|
# Request protections
|
||
|
|
client_max_body_size 10m;
|
||
|
|
send_timeout 30s;
|
||
|
|
proxy_read_timeout 60s;
|
||
|
|
proxy_send_timeout 60s;
|
||
|
|
|
||
|
|
# Basic rate limiting for API
|
||
|
|
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=5r/s;
|
||
|
|
|
||
|
|
# Portal (Next.js)
|
||
|
|
location / {
|
||
|
|
proxy_pass http://frontend:3000;
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
# BFF API
|
||
|
|
location /api/ {
|
||
|
|
proxy_pass http://backend:4000/api/;
|
||
|
|
proxy_http_version 1.1;
|
||
|
|
proxy_set_header Upgrade $http_upgrade;
|
||
|
|
proxy_set_header Connection $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;
|
||
|
|
|
||
|
|
# Apply rate limiting to API only
|
||
|
|
limit_req zone=api_limit burst=10 nodelay;
|
||
|
|
}
|
||
|
|
|
||
|
|
# Health check
|
||
|
|
location /healthz {
|
||
|
|
proxy_pass http://frontend:3000/api/health;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|