# FreeTable Frontend Nginx Configuration # Serves Vue.js static build with SPA fallback worker_processes auto; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; use epoll; multi_accept on; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # Logging 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/xml application/xml+rss text/javascript application/x-javascript; # 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; # Rate limiting zones limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; limit_req_zone $binary_remote_addr zone=static:10m rate=50r/s; # Upstream API backend upstream backend { server ${BACKEND_HOST}:${BACKEND_PORT}; keepalive 32; } server { listen ${PORT}; server_name _; root /usr/share/nginx/html; index index.html; # Security server_tokens off; # Health check endpoint (no caching) location = /health { access_log off; return 200 '{"status":"ok"}'; add_header Content-Type application/json; } # API proxy to backend location /api/ { limit_req zone=api burst=20 nodelay; 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; proxy_set_header Connection ""; # Timeouts proxy_connect_timeout 30s; proxy_send_timeout 60s; proxy_read_timeout 60s; # Buffering proxy_buffering on; proxy_buffer_size 4k; proxy_buffers 8 4k; } # Static assets - long cache for hashed files location /assets/ { limit_req zone=static burst=100 nodelay; expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; } # SPA fallback - all other routes location / { try_files $uri $uri/ /index.html; } # Health check HEALTH_CHECK } }