2026-10-07 21:59:49 +02:00
|
|
|
# Redirect HTTP to HTTPS
|
2025-11-30 10:13:52 +01:00
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
listen [::]:80;
|
2026-10-07 21:59:49 +02:00
|
|
|
server_name example.com www.example.com;
|
2025-11-30 10:13:52 +01:00
|
|
|
|
2026-10-07 21:59:49 +02:00
|
|
|
# Location per la validazione Let's Encrypt
|
2025-11-30 10:13:52 +01:00
|
|
|
location /.well-known/acme-challenge/ {
|
|
|
|
|
root /var/www/certbot;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-07 21:59:49 +02:00
|
|
|
# Redirect tutto il resto a HTTPS
|
2025-11-30 10:13:52 +01:00
|
|
|
location / {
|
2026-10-07 21:59:49 +02:00
|
|
|
return 301 https://$host$request_uri;
|
2025-11-30 10:13:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-10-07 21:59:49 +02:00
|
|
|
|
|
|
|
|
# HTTPS Server
|
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
listen [::]:443 ssl;
|
|
|
|
|
# Il parametro http2 su listen è deprecato dalla 1.25.1: usa la direttiva.
|
|
|
|
|
http2 on;
|
|
|
|
|
server_name example.com www.example.com;
|
|
|
|
|
|
|
|
|
|
# Certificati SSL
|
|
|
|
|
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
|
|
|
|
|
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
|
|
|
|
|
|
|
|
|
|
# Configurazione SSL sicura (profilo Mozilla intermediate)
|
|
|
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
|
# Rimossi i cipher DHE-RSA-*: senza un file ssl_dhparam (nginx >=1.11 non ha
|
|
|
|
|
# parametri DH incorporati) non verrebbero mai negoziati, quindi li togliamo
|
|
|
|
|
# per mantenere la lista onesta. Aggiungi ssl_dhparam (ffdhe2048) se li vuoi.
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
# Session resumption: senza questi ogni nuova connessione fa un full handshake.
|
|
|
|
|
ssl_session_cache shared:SSL:10m;
|
|
|
|
|
ssl_session_timeout 1d;
|
|
|
|
|
ssl_session_tickets off;
|
|
|
|
|
|
|
|
|
|
# Header di sicurezza (HSTS, X-Frame-Options, CSP, ...)
|
|
|
|
|
include /etc/nginx/conf.d/security-headers.inc;
|
|
|
|
|
|
|
|
|
|
# OCSP Stapling rimosso: Let's Encrypt non include più l'URL del responder
|
|
|
|
|
# OCSP (dal 2025) e ha dismesso il servizio, quindi lo stapling non farebbe
|
|
|
|
|
# altro che generare un warning all'avvio.
|
|
|
|
|
|
|
|
|
|
# Nessun access_log/error_log per-vhost: nell'immagine ufficiale solo
|
|
|
|
|
# /var/log/nginx/access.log e error.log sono linkati a stdout/stderr, quindi
|
|
|
|
|
# file dedicati non comparirebbero in "docker-compose logs nginx", crescerebbero
|
|
|
|
|
# senza rotazione e andrebbero persi alla ricreazione del container. Si usa
|
|
|
|
|
# l'access_log a livello http (main) definito in nginx.conf.
|
|
|
|
|
|
|
|
|
|
# Location per la validazione Let's Encrypt
|
|
|
|
|
location /.well-known/acme-challenge/ {
|
|
|
|
|
root /var/www/certbot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Blocca l'actuator/metrics JHipster dall'esterno (health, prometheus, info...).
|
|
|
|
|
# L'endpoint health serve solo all'healthcheck interno al container.
|
|
|
|
|
# ^~ : disabilita il match delle location regex per questo prefisso (altrimenti
|
|
|
|
|
# un URI /management/...qualcosa.js verrebbe gestito da una location regex).
|
|
|
|
|
# Senza slash finale copre sia "/management" (pagina di discovery dell'actuator)
|
|
|
|
|
# sia "/management/...".
|
|
|
|
|
location ^~ /management {
|
|
|
|
|
return 404;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Resolver Docker interno per risolvere l'hostname a ogni richiesta.
|
|
|
|
|
# Senza questo, proxy_pass con hostname letterale viene risolto una sola
|
|
|
|
|
# volta all'avvio: dopo un "docker-compose up -d" il container blog puo'
|
|
|
|
|
# ottenere un nuovo IP e nginx continuerebbe a puntare a quello vecchio
|
|
|
|
|
# (errori 502) finche' non viene riavviato.
|
|
|
|
|
resolver 127.0.0.11 valid=30s ipv6=off;
|
|
|
|
|
|
|
|
|
|
# Proxy verso l'applicazione Java
|
|
|
|
|
location / {
|
|
|
|
|
# Usare una variabile forza nginx a risolvere l'upstream a runtime
|
|
|
|
|
# tramite il resolver sopra, invece che una sola volta all'avvio.
|
|
|
|
|
set $upstream_blog http://blog:8080;
|
|
|
|
|
proxy_pass $upstream_blog;
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
|
|
|
|
|
# Headers per preservare informazioni client
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
# WebSocket support (se necessario): invia "upgrade" solo quando richiesto
|
|
|
|
|
# tramite la map $connection_upgrade definita in nginx.conf.
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
proxy_set_header Connection $connection_upgrade;
|
|
|
|
|
|
|
|
|
|
# Timeout
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Le risorse statiche sono servite dallo stesso location / sopra: JHipster
|
|
|
|
|
# imposta gia' gli header di cache corretti (con max-age e hash nei nomi
|
|
|
|
|
# file dove appropriato), quindi non serve un location dedicato che
|
|
|
|
|
# duplicherebbe/entrebbe in conflitto con quegli header.
|
|
|
|
|
}
|