chore: update
This commit is contained in:
+135
-44
@@ -1,79 +1,170 @@
|
||||
upstream backend {
|
||||
server 127.0.0.1:{{ backend_port }} max_fails=3 fail_timeout=30s;
|
||||
keepalive 32;
|
||||
# =========================================================
|
||||
# Request ID for correlation
|
||||
# =========================================================
|
||||
map $http_x_request_id $req_id {
|
||||
default $http_x_request_id;
|
||||
"" $request_id;
|
||||
}
|
||||
|
||||
# =========================================================
|
||||
# Rate limiting
|
||||
# =========================================================
|
||||
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/m;
|
||||
limit_req_zone $binary_remote_addr zone=uploads:10m rate=10r/m;
|
||||
|
||||
# =========================================================
|
||||
# Upstream backend
|
||||
# =========================================================
|
||||
upstream backend {
|
||||
server 127.0.0.1:{{ backend_local_port }} max_fails=3 fail_timeout=30s;
|
||||
keepalive 32;
|
||||
keepalive_requests 100;
|
||||
keepalive_timeout 60s;
|
||||
}
|
||||
|
||||
{% if ssl_enabled %}
|
||||
# =========================================================
|
||||
# HTTP → HTTPS redirect
|
||||
# =========================================================
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name {{ nginx_domain }};
|
||||
root {{ nginx_frontend_path }}/dist;
|
||||
index index.html;
|
||||
server_name {{ domain_name }};
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
access_log /var/log/nginx/{{ nginx_app_name }}.access.log;
|
||||
error_log /var/log/nginx/{{ nginx_app_name }}.error.log;
|
||||
# =========================================================
|
||||
# API Server
|
||||
# =========================================================
|
||||
server {
|
||||
{% if ssl_enabled %}
|
||||
listen {{ backend_port }} ssl;
|
||||
listen [::]:{{ backend_port }} ssl;
|
||||
|
||||
ssl_certificate /etc/letsencrypt/live/{{ domain_name }}/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/{{ domain_name }}/privkey.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;
|
||||
ssl_prefer_server_ciphers off;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_session_tickets off;
|
||||
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
|
||||
{% else %}
|
||||
listen {{ backend_port }};
|
||||
listen [::]:{{ backend_port }};
|
||||
{% endif %}
|
||||
|
||||
server_name {{ domain_name }};
|
||||
client_max_body_size {{ nginx_max_body_size }};
|
||||
|
||||
location /api/ {
|
||||
limit_except GET POST PUT DELETE PATCH OPTIONS {
|
||||
deny all;
|
||||
}
|
||||
server_tokens off;
|
||||
|
||||
proxy_pass http://backend/;
|
||||
# =========================================================
|
||||
# Security headers
|
||||
# =========================================================
|
||||
add_header X-Frame-Options "DENY" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
proxy_hide_header X-Powered-By;
|
||||
proxy_hide_header Server;
|
||||
|
||||
# =========================================================
|
||||
# API proxy
|
||||
# =========================================================
|
||||
location / {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
|
||||
limit_except GET POST PUT PATCH DELETE OPTIONS { deny all; }
|
||||
|
||||
proxy_pass http://backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
|
||||
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-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;
|
||||
|
||||
proxy_buffering on;
|
||||
proxy_buffer_size 4k;
|
||||
proxy_buffers 8 4k;
|
||||
proxy_no_cache 1;
|
||||
proxy_cache_bypass 1;
|
||||
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";
|
||||
}
|
||||
# =========================================================
|
||||
# Uploads
|
||||
# =========================================================
|
||||
location /uploads/ {
|
||||
alias {{ uploads_dir }}/;
|
||||
limit_req zone=uploads burst=20 nodelay;
|
||||
limit_except GET HEAD { deny all; }
|
||||
|
||||
location ~* \.(css|js)$ {
|
||||
expires {{ nginx_cache_static_duration }};
|
||||
# Bloquer les fichiers exécutables
|
||||
location ~* \.(php|php5|phtml|sh|py|pl|cgi|exe|asp|aspx|jsp)$ {
|
||||
deny all;
|
||||
}
|
||||
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
access_log off;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
}
|
||||
|
||||
location ~* \.(jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires {{ nginx_cache_media_duration }};
|
||||
add_header Cache-Control "public, immutable";
|
||||
access_log off;
|
||||
location ^~ /uploads/images/ {
|
||||
alias {{ uploads_dir }}/images/;
|
||||
limit_req zone=uploads burst=20 nodelay;
|
||||
limit_except GET HEAD OPTIONS { deny all; }
|
||||
|
||||
add_header Access-Control-Allow-Origin "*" always;
|
||||
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
|
||||
add_header X-Content-Type-Options "nosniff" 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 = /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
location ^~ /uploads/videos/ {
|
||||
alias {{ uploads_dir }}/videos/;
|
||||
limit_req zone=uploads burst=20 nodelay;
|
||||
limit_except GET HEAD OPTIONS { deny all; }
|
||||
|
||||
add_header Access-Control-Allow-Origin "*" always;
|
||||
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
|
||||
add_header X-Content-Type-Options "nosniff" 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;
|
||||
|
||||
# =========================================================
|
||||
# Deny hidden files and sensitive files
|
||||
# =========================================================
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
location ~* (\.env|\.git|package\.json|package-lock\.json|yarn\.lock)$ {
|
||||
location ~* (\.env|\.git|package\.json|package-lock\.json|yarn\.lock|Dockerfile|docker-compose\.yml)$ {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user