|
| 1 | +events { |
| 2 | + worker_connections 1024; |
| 3 | +} |
| 4 | + |
| 5 | +http { |
| 6 | + include /etc/nginx/mime.types; |
| 7 | + default_type application/octet-stream; |
| 8 | + |
| 9 | + # Logging |
| 10 | + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
| 11 | + '$status $body_bytes_sent "$http_referer" ' |
| 12 | + '"$http_user_agent" "$http_x_forwarded_for"'; |
| 13 | + |
| 14 | + access_log /var/log/nginx/access.log main; |
| 15 | + error_log /var/log/nginx/error.log; |
| 16 | + |
| 17 | + # Gzip compression |
| 18 | + gzip on; |
| 19 | + gzip_vary on; |
| 20 | + gzip_min_length 1024; |
| 21 | + gzip_proxied any; |
| 22 | + gzip_comp_level 6; |
| 23 | + gzip_types |
| 24 | + text/plain |
| 25 | + text/css |
| 26 | + text/xml |
| 27 | + text/javascript |
| 28 | + application/json |
| 29 | + application/javascript |
| 30 | + application/xml+rss |
| 31 | + application/atom+xml |
| 32 | + image/svg+xml; |
| 33 | + |
| 34 | + # Security headers |
| 35 | + add_header X-Frame-Options "SAMEORIGIN" always; |
| 36 | + add_header X-Content-Type-Options "nosniff" always; |
| 37 | + add_header X-XSS-Protection "1; mode=block" always; |
| 38 | + add_header Referrer-Policy "strict-origin-when-cross-origin" always; |
| 39 | + |
| 40 | + server { |
| 41 | + listen 80; |
| 42 | + server_name localhost; |
| 43 | + root /usr/share/nginx/html; |
| 44 | + index index.html; |
| 45 | + |
| 46 | + # Handle static assets |
| 47 | + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|webp|woff|woff2|ttf|eot)$ { |
| 48 | + expires 1y; |
| 49 | + add_header Cache-Control "public, immutable"; |
| 50 | + try_files $uri =404; |
| 51 | + } |
| 52 | + |
| 53 | + # Handle Next.js static export routes |
| 54 | + location / { |
| 55 | + try_files $uri $uri/index.html /index.html; |
| 56 | + } |
| 57 | + |
| 58 | + # Specific route handling for better performance |
| 59 | + location = /physarum { |
| 60 | + try_files /physarum/index.html /index.html; |
| 61 | + } |
| 62 | + |
| 63 | + location = /tree { |
| 64 | + try_files /tree/index.html /index.html; |
| 65 | + } |
| 66 | + |
| 67 | + location = /pool { |
| 68 | + try_files /pool/index.html /index.html; |
| 69 | + } |
| 70 | + |
| 71 | + # Handle routes with trailing slash |
| 72 | + location ~ ^/(physarum|tree|pool)/$ { |
| 73 | + try_files $uri/index.html /index.html; |
| 74 | + } |
| 75 | + |
| 76 | + # Handle 404 errors |
| 77 | + error_page 404 /404.html; |
| 78 | + location = /404.html { |
| 79 | + internal; |
| 80 | + } |
| 81 | + |
| 82 | + # Health check endpoint |
| 83 | + location /health { |
| 84 | + access_log off; |
| 85 | + return 200 "healthy\n"; |
| 86 | + add_header Content-Type text/plain; |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments