Files
lincodex/deploy/edge/nginx/lincodex-https.conf.template
T

94 lines
4.0 KiB
Plaintext

# Port 443 for {{EDGE_DOMAIN}}: TLS termination and a reverse proxy to the
# frontend container of the app host, reached through the AmneziaWG tunnel.
# The frontend container serves the SPA (including the index.html fallback
# for deep links) and proxies /api to the Go backend, so this proxy forwards
# every path unchanged and both live on one origin.
#
# Rendered from deploy/edge/nginx/lincodex-https.conf.template. Needs the
# certificate from certbot; install it only after the first issuance.
upstream lincodex_app {
server {{EDGE_UPSTREAM}};
# Reused connections to the app host; the tunnel round trip is the
# expensive part of a request.
keepalive 16;
}
server {
listen {{EDGE_LISTEN_IP}}:443 ssl;
# No HTTP/3: QUIC would need UDP 443, which another service on this host
# already owns.
http2 on;
server_name {{EDGE_DOMAIN}};
server_tokens off;
access_log /var/log/nginx/lincodex.access.log lincodex;
ssl_certificate /etc/letsencrypt/live/{{EDGE_CERT_NAME}}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{EDGE_CERT_NAME}}/privkey.pem;
# Mozilla "intermediate" profile: TLS 1.2 and 1.3, AEAD suites with
# forward secrecy. The client picks the suite (prefer_server_ciphers off).
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:DHE-RSA-CHACHA20-POLY1305;
ssl_prefer_server_ciphers off;
ssl_session_timeout 1d;
ssl_session_cache shared:lincodex_tls:10m;
# Tickets would keep one long-lived key that undoes forward secrecy.
ssl_session_tickets off;
# OCSP stapling is deliberately absent: Let's Encrypt certificates no
# longer carry an OCSP responder URL, so there is nothing to staple.
# HSTS without preload. The header is set at server level only; a nested
# add_header in a location would drop it.
add_header Strict-Transport-Security "max-age={{EDGE_HSTS_MAX_AGE}}; includeSubDomains" always;
# Largest accepted request body. The resume upload limit is 5 MB; the
# frontend container allows 1 MB by default and more only on a route that
# needs it (never above 10 MB), and this value must not be lower than any
# of those limits.
client_max_body_size {{EDGE_MAX_BODY}};
client_header_timeout 15s;
client_body_timeout 60s;
send_timeout 60s;
# Compression for the static shell only. gzip over responses that mix
# secrets with attacker-influenced content enables BREACH, so JSON is not
# in gzip_types and the API location turns compression off outright.
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types text/css text/javascript application/javascript image/svg+xml;
proxy_http_version 1.1;
# Clear Connection so the upstream keepalive pool is used.
proxy_set_header Connection "";
# Host is preserved: the backend and the frontend container see the public
# name, which is what origin and link checks compare against.
proxy_set_header Host $host;
# The edge is the first trusted hop, so it replaces client-supplied
# forwarding headers instead of appending to them.
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
# A client-supplied Forwarded header would be a second, unchecked source
# of the client address.
proxy_set_header Forwarded "";
proxy_redirect off;
proxy_connect_timeout 5s;
proxy_send_timeout 60s;
# The frontend container gives the backend 30 s; leave room for it.
proxy_read_timeout 60s;
location ^~ /api/ {
gzip off;
proxy_pass http://lincodex_app;
}
location / {
proxy_pass http://lincodex_app;
}
}