Files
projet_gestion_commande/ansible/templates/nginx-frontend.conf.j2
T
2026-03-03 23:42:23 +01:00

192 lines
6.0 KiB
Django/Jinja

# =========================================================
# Request ID for correlation
# =========================================================
map $http_x_request_id $req_id {
default $http_x_request_id;
"" $request_id;
}
# =========================================================
# Backend distant
# =========================================================
upstream backend {
server uber-stup.club:443;
keepalive 32;
}
{% if ssl_enabled %}
# =========================================================
# HTTP → HTTPS redirect + ACME challenge
# =========================================================
server {
listen 80;
listen [::]:80;
server_name {{ domain_name }};
# Certbot renouvellement automatique
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
# =========================================================
# HTTPS Server
# =========================================================
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name {{ domain_name }};
# =========================================================
# SSL/TLS - Let's Encrypt
# =========================================================
ssl_certificate /etc/letsencrypt/live/{{ domain_name }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ domain_name }}/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/{{ domain_name }}/chain.pem;
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;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 8.8.8.8 valid=300s;
resolver_timeout 5s;
{% else %}
# =========================================================
# HTTP Server (phase pré-certificat)
# =========================================================
server {
listen 80;
listen [::]:80;
server_name {{ domain_name }};
# ACME challenge accessible avant l'émission du certificat
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
{% endif %}
root {{ frontend_dir }}/dist;
index index.html;
client_max_body_size {{ nginx_max_body_size }};
location /api/ {
limit_except GET POST PUT PATCH DELETE OPTIONS { deny all; }
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, PATCH, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, X-Request-ID' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Max-Age' 86400 always;
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain charset=UTF-8';
return 204;
}
proxy_pass https://backend;
proxy_http_version 1.1;
proxy_ssl_server_name on;
proxy_ssl_name uber-stup.club;
proxy_set_header Host uber-stup.club;
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-Request-ID $req_id;
proxy_set_header Connection "";
proxy_connect_timeout {{ nginx_proxy_timeout }}s;
proxy_send_timeout {{ nginx_proxy_timeout }}s;
proxy_read_timeout {{ nginx_proxy_timeout }}s;
}
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
add_header Pragma "no-cache" always;
add_header Expires "0" always;
}
location /uploads/ {
alias {{ uploads_dir }}/;
expires 30d;
add_header Cache-Control "public, immutable";
}
location ^~ /uploads/images/ {
alias {{ uploads_dir }}/images/;
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
expires 30d;
add_header Cache-Control "public, immutable" always;
types {
image/jpeg jpg jpeg;
image/png png;
image/gif gif;
image/webp webp;
image/svg+xml svg;
}
default_type image/jpeg;
}
location ^~ /uploads/videos/ {
alias {{ uploads_dir }}/videos/;
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
expires 30d;
add_header Cache-Control "public, immutable" always;
types {
video/mp4 mp4;
video/webm webm;
video/ogg ogv;
}
default_type video/mp4;
}
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;
{% if ssl_enabled %}
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
{% endif %}
add_header Content-Security-Policy "
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
img-src 'self' data: https:;
font-src 'self' data:;
connect-src 'self' https://api.tomtom.com https://uber-stup.club;
" always;
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~* (\.env|\.git|package\.json|package-lock\.json|yarn\.lock|Dockerfile|docker-compose\.yml)$ {
deny all;
access_log off;
log_not_found off;
}
}