Refactor SPA fallback handling in nginx configuration for improved routing

This commit is contained in:
Tudor Stanciu 2025-09-29 01:03:26 +03:00
parent 52f511e271
commit 0bfbe6e9f2

View File

@ -51,15 +51,11 @@ http {
add_header Cache-Control "public, immutable"; add_header Cache-Control "public, immutable";
} }
# SPA fallback - catch all routes and serve appropriate index.html # SPA fallback - handle client-side routing for React apps
location / { location / {
try_files $uri $uri/ @fallback; # First try to serve request as file, then as directory
} # If both fail, serve index.html for SPA routing
try_files $uri $uri/ /index.html;
# Fallback handler for SPA routes
location @fallback {
# Try to find index.html in the same directory structure
try_files $uri/index.html /index.html;
} }
# Health check endpoint # Health check endpoint