212 lignes
8.3 KiB
Plaintext
212 lignes
8.3 KiB
Plaintext
# ==============================================================================
|
|
# Nginx — Configuration VPS Suisse (Bouclier Reverse-Proxy & Statique AOT)
|
|
# Domaine : gastinel.me / www.gastinel.me
|
|
# Cible : VPS Suisse (Alpine / Debian 12) devant Livebox résidentielle
|
|
# ==============================================================================
|
|
|
|
# Note : Si compilé avec le module ngx_brotli (recommandé : nginx:alpine-brotli ou ppa:ondrej/nginx)
|
|
# load_module modules/ngx_http_brotli_filter_module.so;
|
|
# load_module modules/ngx_http_brotli_static_module.so;
|
|
|
|
# Limite de requêtes sur les API proxifiées
|
|
limit_req_zone $binary_remote_addr zone=api_ratelimit:10m rate=5r/s;
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 1. Redirection HTTP vers HTTPS (Port 80 -> 443)
|
|
# ------------------------------------------------------------------------------
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name gastinel.me www.gastinel.me;
|
|
|
|
# Défi ACME Let's Encrypt / Certbot
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/certbot;
|
|
}
|
|
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# 2. Serveur Principal HTTPS (TLS 1.3 Exclusif & HTTP/2 / HTTP/3 QUIC)
|
|
# ------------------------------------------------------------------------------
|
|
server {
|
|
listen 443 ssl;
|
|
listen [::]:443 ssl;
|
|
# Nginx 1.25+ supporte la directive native http2 on;
|
|
http2 on;
|
|
|
|
# Option HTTP/3 QUIC (décommenter si Nginx 1.25+ compilé avec --with-http_v3_module) :
|
|
# listen 443 quic reuseport;
|
|
# listen [::]:443 quic reuseport;
|
|
# add_header Alt-Svc 'h3=":443"; ma=86400' always;
|
|
|
|
server_name gastinel.me www.gastinel.me;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# ---- Certificats & Durcissement TLS --------------------------------------
|
|
ssl_certificate /etc/letsencrypt/live/gastinel.me/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/gastinel.me/privkey.pem;
|
|
|
|
# TLS 1.3 EXCLUSIF (élimine toute vulnérabilité héritée et réduit les allers-retours handshake)
|
|
ssl_protocols TLSv1.3;
|
|
ssl_prefer_server_ciphers off;
|
|
ssl_ecdh_curve X25519:prime256v1;
|
|
|
|
# Optimisation de session SSL (0-RTT / Fast Resumption sécurisé)
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 1d;
|
|
ssl_session_tickets off;
|
|
|
|
# Résolveur DNS local avec validation DNSSEC pour OCSP Stapling
|
|
ssl_stapling on;
|
|
ssl_stapling_verify on;
|
|
resolver 1.1.1.1 9.9.9.9 valid=300s;
|
|
resolver_timeout 5s;
|
|
|
|
# ---- Masquage du serveur & Optimisation TCP Système ----------------------
|
|
server_tokens off;
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout 65;
|
|
types_hash_max_size 2048;
|
|
|
|
client_body_buffer_size 16k;
|
|
client_header_buffer_size 1k;
|
|
client_max_body_size 2m;
|
|
large_client_header_buffers 4 8k;
|
|
|
|
# ---- En-têtes HTTP de Sécurité Stricts (Grade A+) -----------------------
|
|
# 1. HSTS (2 ans + sous-domaines + éligible preload list HSTS)
|
|
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
|
|
|
|
# 2. Protection contre le sniffing de type MIME
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
|
|
# 3. Interdiction d'encapsulation (Clickjacking)
|
|
add_header X-Frame-Options "DENY" always;
|
|
|
|
# 4. Politique de Referrer étanche
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# 5. Désactivation des API matérielles intrusives
|
|
add_header Permissions-Policy "geolocation=(), camera=(), microphone=(), payment=(), usb=()" always;
|
|
|
|
# 6. Content-Security-Policy (CSP) statique épuré
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' https://news.gastinel.me; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests;" always;
|
|
|
|
# ---- Compression Extrême AOT (Brotli Statique 11 & Gzip Statique 9) -----
|
|
# Nginx sert directement les fichiers .br et .gz générés hors-ligne (zéro CPU)
|
|
brotli_static on;
|
|
gzip_static on;
|
|
|
|
# Repli dynamique à la volée si le fichier statique n'a pas été pré-compressé
|
|
brotli on;
|
|
brotli_comp_level 6;
|
|
brotli_types text/plain text/css application/javascript application/json image/svg+xml;
|
|
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 256;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
|
|
|
|
# ---- Politiques de Cache HTTP --------------------------------------------
|
|
# 1. Assets immuables (images WebP, polices Inter & Comfortaa WOFF2)
|
|
location /assets/ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, max-age=31536000, immutable" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
access_log off;
|
|
}
|
|
|
|
# 2. Document HTML (index.html) : 5 minutes avec stale-while-revalidate
|
|
# Assure une mise à jour quasi-instantanée sans forcer le rechargement lourd
|
|
location = / {
|
|
add_header Cache-Control "public, max-age=300, stale-while-revalidate=60" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-Frame-Options "DENY" always;
|
|
try_files /index.html =404;
|
|
}
|
|
|
|
location = /index.html {
|
|
add_header Cache-Control "public, max-age=300, stale-while-revalidate=60" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-Frame-Options "DENY" always;
|
|
}
|
|
|
|
# 3. Flux d'actualités (data/news.json) : 5 minutes de cache
|
|
location = /data/news.json {
|
|
add_header Cache-Control "public, max-age=300, stale-while-revalidate=60" always;
|
|
add_header Content-Type "application/json; charset=utf-8" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header Access-Control-Allow-Origin "https://gastinel.me" always;
|
|
}
|
|
|
|
# ---- Reverse-Proxy Sécurisé vers Backend Livebox (Télémétrie & API) -----
|
|
# IMPORTANT : L'IP résidentielle de la Livebox n'apparaît JAMAIS publiquement.
|
|
# La communication transite EXCLUSIVEMENT par le tunnel chiffré WireGuard (10.8.0.2).
|
|
|
|
# Intercepter les erreurs pour servir une page 502/504 locale au VPS
|
|
# Empêche tout équipement résidentiel Orange/Livebox de signer une page d'erreur
|
|
proxy_intercept_errors on;
|
|
error_page 502 503 504 /50x.html;
|
|
location = /50x.html {
|
|
root /usr/share/nginx/html;
|
|
internal;
|
|
}
|
|
|
|
location /api/stats {
|
|
limit_except GET { deny all; }
|
|
limit_req zone=api_ratelimit burst=10 nodelay;
|
|
|
|
# Adresse IP interne du serveur local dans le tunnel WireGuard
|
|
proxy_pass http://10.8.0.2:8085;
|
|
proxy_http_version 1.1;
|
|
|
|
# Masquage strict de l'origine et des signatures du backend
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $remote_addr;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Connection "";
|
|
|
|
# Suppression impérative de tout en-tête fuitant du backend
|
|
proxy_hide_header X-Powered-By;
|
|
proxy_hide_header Server;
|
|
proxy_hide_header Via;
|
|
proxy_hide_header X-Varnish;
|
|
proxy_hide_header X-Runtime;
|
|
proxy_hide_header X-Backend-Server;
|
|
|
|
# Micro-cache de 2 secondes pour immuniser la Livebox contre les pics
|
|
add_header Cache-Control "public, max-age=2, stale-while-revalidate=1" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
}
|
|
|
|
location /api/assistant {
|
|
limit_except POST OPTIONS { deny all; }
|
|
limit_req zone=api_ratelimit burst=5 nodelay;
|
|
|
|
proxy_pass http://10.8.0.2:8085;
|
|
proxy_http_version 1.1;
|
|
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $remote_addr;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Connection "";
|
|
|
|
proxy_hide_header X-Powered-By;
|
|
proxy_hide_header Server;
|
|
proxy_hide_header Via;
|
|
|
|
add_header Cache-Control "no-store, no-cache, must-revalidate" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
}
|
|
}
|