Files
projet_gestion_commande/docker/frontend/nginx.conf
T

158 lines
4.9 KiB
Nginx Configuration File

# =========================================================
# Request ID for correlation
# =========================================================
map $http_x_request_id $req_id {
default $http_x_request_id;
"" $request_id;
}
# =========================================================
# Upstream backend
# =========================================================
upstream backend {
server backend:8080 max_fails=3 fail_timeout=30s;
keepalive 32;
keepalive_requests 100;
keepalive_timeout 60s;
}
# =========================================================
# HTTP Server (MAIN)
# =========================================================
# Supprime le premier server block et garde seulement :
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
index index.html;
client_max_body_size 10M;
modsecurity on;
modsecurity_rules_file /etc/nginx/modsec/custom-rules.conf;
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 http://backend;
proxy_http_version 1.1;
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; # ✅ Changé
proxy_set_header X-Request-ID $req_id;
proxy_set_header Connection "";
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
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/ {
# ✅ IMPORTANT : alias doit se terminer par / ET le chemin aussi
alias /usr/share/nginx/html/uploads/;
# ✅ Désactiver ModSecurity pour les uploads
modsecurity off;
# Cache headers
expires 30d;
add_header Cache-Control "public, immutable";
}
location ^~ /uploads/images/ {
alias /usr/share/nginx/html/uploads/images/;
# ✅ Désactiver ModSecurity
modsecurity off;
# ✅ CORS pour images publiques
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
# Cache agressif
expires 30d;
add_header Cache-Control "public, immutable" always;
# Types MIME
types {
image/jpeg jpg jpeg;
image/png png;
image/gif gif;
image/webp webp;
image/svg+xml svg;
}
default_type image/jpeg;
}
# =========================================================
# ✅ UPLOADS VIDEOS (priorité maximale avec ^~)
# =========================================================
location ^~ /uploads/videos/ {
alias /usr/share/nginx/html/uploads/videos/;
# ✅ Désactiver ModSecurity
modsecurity off;
# ✅ CORS pour vidéos publiques
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
# Cache agressif
expires 30d;
add_header Cache-Control "public, immutable" always;
# Types MIME pour vidéos
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;
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;
" 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;
}
}