fix: Improve nginx configuration for React SPA routing
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
59e270e3ca
commit
7ae458f768
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user