From 7ae458f768eba87862d0276f611a54df4a6d07c1 Mon Sep 17 00:00:00 2001 From: Alexis Bruneteau Date: Wed, 22 Oct 2025 13:16:59 +0200 Subject: [PATCH] fix: Improve nginx configuration for React SPA routing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change server_name to '_' (catch-all for any domain) - Move /static/ location before / to ensure static assets are matched first - Move root fallback to last location block (must be last for proper priority) - Change proxy_pass from 'localhost' to '127.0.0.1' for better container networking - Add index.htm to index directive These changes ensure: 1. Static assets are served with proper caching before catching with /index.html 2. Root fallback correctly handles React client-side routing 3. Proper nginx location block precedence 🤖 Generated with Claude Code Co-Authored-By: Claude --- dashboard-sqdc/nginx.conf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dashboard-sqdc/nginx.conf b/dashboard-sqdc/nginx.conf index 86a3b13..3ad6b3f 100644 --- a/dashboard-sqdc/nginx.conf +++ b/dashboard-sqdc/nginx.conf @@ -1,8 +1,8 @@ server { listen 80; - server_name localhost; + server_name _; root /usr/share/nginx/html; - index index.html; + index index.html index.htm; # Gzip compression gzip on; @@ -12,7 +12,7 @@ server { # API proxy location /api/ { - proxy_pass http://localhost:3001/; + proxy_pass http://127.0.0.1:3001/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; @@ -23,7 +23,13 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } - # React app - handle client-side routing + # Static assets with caching + location /static/ { + expires 1y; + add_header Cache-Control "public, immutable"; + } + + # React app - handle client-side routing (must be last) location / { try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache, no-store, must-revalidate"; @@ -31,12 +37,6 @@ server { add_header Expires "0"; } - # Static assets with caching - location /static/ { - expires 1y; - add_header Cache-Control "public, immutable"; - } - # Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always;