| 1 | worker_processes auto; |
| 2 | error_log /var/log/nginx/error.log warn; |
| 3 | pid /var/run/nginx.pid; |
| 4 | |
| 5 | events { |
| 6 | worker_connections 1024; |
| 7 | } |
| 8 | |
| 9 | http { |
| 10 | include /etc/nginx/mime.types; |
| 11 | default_type application/octet-stream; |
| 12 | |
| 13 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
| 14 | '$status $body_bytes_sent "$http_referer" ' |
| 15 | '"$http_user_agent" "$http_x_forwarded_for"'; |
| 16 | |
| 17 | access_log /var/log/nginx/access.log main; |
| 18 | |
| 19 | sendfile on; |
| 20 | tcp_nopush on; |
| 21 | tcp_nodelay on; |
| 22 | keepalive_timeout 65; |
| 23 | types_hash_max_size 2048; |
| 24 | client_max_body_size 100M; |
| 25 | |
| 26 | gzip on; |
| 27 | gzip_vary on; |
| 28 | gzip_proxied any; |
| 29 | gzip_comp_level 6; |
| 30 | gzip_types text/plain text/css text/xml text/javascript |
| 31 | application/json application/javascript application/xml+rss |
| 32 | application/rss+xml font/truetype font/opentype |
| 33 | application/vnd.ms-fontobject image/svg+xml; |
| 34 | |
| 35 | server { |
| 36 | listen 80; |
| 37 | server_name _; |
| 38 | root /usr/share/nginx/html; |
| 39 | index index.html; |
| 40 | |
| 41 | # Security headers |
| 42 | add_header X-Frame-Options "SAMEORIGIN" always; |
| 43 | add_header X-Content-Type-Options "nosniff" always; |
| 44 | add_header X-XSS-Protection "1; mode=block" always; |
| 45 | add_header Referrer-Policy "no-referrer-when-downgrade" always; |
| 46 | |
| 47 | # Cache static assets |
| 48 | location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ { |
| 49 | expires 1y; |
| 50 | add_header Cache-Control "public, immutable"; |
| 51 | } |
| 52 | |
| 53 | # Handle SPA routing - serve index.html for all routes |
| 54 | location / { |
| 55 | try_files $uri $uri/ /index.html; |
| 56 | } |
| 57 | |
| 58 | # API proxy (adjust backend URL as needed) |
| 59 | location /api { |
| 60 | proxy_pass http://copilot-backend:5000; |
| 61 | proxy_http_version 1.1; |
| 62 | proxy_set_header Upgrade $http_upgrade; |
| 63 | proxy_set_header Connection 'upgrade'; |
| 64 | proxy_set_header Host $host; |
| 65 | proxy_set_header X-Real-IP $remote_addr; |
| 66 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 67 | proxy_set_header X-Forwarded-Proto $scheme; |
| 68 | proxy_cache_bypass $http_upgrade; |
| 69 | proxy_read_timeout 300; |
| 70 | proxy_connect_timeout 300; |
| 71 | proxy_send_timeout 300; |
| 72 | } |
| 73 | |
| 74 | # Health check endpoint |
| 75 | location /health { |
| 76 | access_log off; |
| 77 | return 200 "healthy\n"; |
| 78 | add_header Content-Type text/plain; |
| 79 | } |
| 80 | |
| 81 | # Error pages |
| 82 | error_page 404 /index.html; |
| 83 | error_page 500 502 503 504 /50x.html; |
| 84 | location = /50x.html { |
| 85 | root /usr/share/nginx/html; |
| 86 | } |
| 87 | } |
| 88 | } |