132 lines
4.4 KiB
Nginx Configuration File
132 lines
4.4 KiB
Nginx Configuration File
# ─── EnFlow Nginx Configuration ────────────────────────────────────────────
|
|
|
|
user nginx;
|
|
worker_processes auto;
|
|
error_log /var/log/nginx/error.log warn;
|
|
pid /var/run/nginx.pid;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
# Logging format
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
|
|
# Performance
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout 65;
|
|
types_hash_max_size 2048;
|
|
|
|
# Gzip compression
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
|
|
|
# Rate limiting zones
|
|
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s;
|
|
limit_req_zone $binary_remote_addr zone=general:10m rate=100r/s;
|
|
|
|
# Upstream to Next.js app
|
|
upstream enflow_app {
|
|
server enflow-app:3000;
|
|
}
|
|
|
|
# ─── HTTP → HTTPS Redirect ───────────────────────────────────────────────
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
|
|
# Certbot challenge
|
|
location /.well-known/acme-challenge/ {
|
|
root /var/www/certbot;
|
|
}
|
|
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
# ─── HTTPS Server ────────────────────────────────────────────────────────
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name _;
|
|
|
|
# SSL certificates (mount via certbot volume)
|
|
ssl_certificate /etc/letsencrypt/live/cirux.silvioalzate.shop/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/cirux.silvioalzate.shop/privkey.pem;
|
|
|
|
# SSL settings
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
|
ssl_prefer_server_ciphers on;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 1d;
|
|
|
|
# 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;
|
|
|
|
# Proxy to Next.js
|
|
location / {
|
|
limit_req zone=general burst=50 nodelay;
|
|
proxy_pass http://enflow_app;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection 'upgrade';
|
|
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_cache_bypass $http_upgrade;
|
|
proxy_read_timeout 86400;
|
|
}
|
|
|
|
# API routes with stricter rate limiting
|
|
location /api/ {
|
|
limit_req zone=api burst=20 nodelay;
|
|
proxy_pass http://enflow_app;
|
|
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;
|
|
}
|
|
|
|
# Static files caching
|
|
location /_next/static/ {
|
|
proxy_pass http://enflow_app;
|
|
proxy_cache_valid 200 365d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
location /static/ {
|
|
proxy_pass http://enflow_app;
|
|
proxy_cache_valid 200 365d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# WebSocket support for Supabase Realtime
|
|
location /realtime/ {
|
|
proxy_pass http://enflow_app;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_read_timeout 86400;
|
|
}
|
|
}
|
|
}
|