← Retour
# ═══════════════════════════════════════════════════════════════════════════
# {{NAME}} - Static Site / SPA Configuration
# Auto-generated by smart-deploy.sh
# ═══════════════════════════════════════════════════════════════════════════
# Redirect HTTP to HTTPS
server {
listen 80;
server_name {{DOMAIN}};
return 301 https://$server_name$request_uri;
}
# HTTPS Server
server {
listen 443 ssl http2;
server_name {{DOMAIN}};
# SSL Configuration
ssl_certificate {{SSL_CERT}};
ssl_certificate_key {{SSL_KEY}};
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
# Security Headers
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;
# Logging
access_log /var/log/nginx/{{NAME}}.access.log;
error_log /var/log/nginx/{{NAME}}.error.log;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# Static assets with long cache
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|webp|avif)$ {
proxy_pass http://{{BACKEND}}:{{PORT}};
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;
# Cache for 1 year (immutable assets)
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# HTML with short cache (for SPA)
location ~* \.html$ {
proxy_pass http://{{BACKEND}}:{{PORT}};
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;
# No cache for HTML
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
expires 0;
}
# Main location (SPA fallback)
location / {
proxy_pass http://{{BACKEND}}:{{PORT}};
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;
# SPA: try files then fallback to index.html
# Note: This is handled by the container's nginx/node
proxy_intercept_errors on;
error_page 404 = /index.html;
}
# Health check
location /health {
proxy_pass http://{{BACKEND}}:{{PORT}}/health;
proxy_set_header Host $host;
access_log off;
}
}