From 415abcd74e4fd95072e7869135781c49dbaf2bc8 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Tue, 9 Jun 2026 23:42:11 +0000 Subject: [PATCH] Add nginx.conf --- nginx.conf | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 nginx.conf diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..de89e3e --- /dev/null +++ b/nginx.conf @@ -0,0 +1,108 @@ +# 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; + } + } +} \ No newline at end of file