🐛(frontend) fix Nginx configuration for SPA routing with Vite

Configured Nginx to serve index.html for all requests, allowing
the client-side router (Wouter) to manage the routing.

Added a try_files directive to attempt to serve static files first,
falling back to index.html if the requested file is not found.

Added an error_page directive to handle 404 errors by internally
redirecting to index.html without modifying the URL path.

Wouter should make the rest.
This commit is contained in:
antoine lebaud
2024-07-11 20:15:20 +02:00
committed by aleb_the_flash
parent 6e3bf3b5f4
commit eac107aac6

View File

@@ -4,12 +4,16 @@ server {
root /usr/share/nginx/html;
# Serve static files
location / {
try_files $uri index.html $uri/ =404;
try_files $uri $uri/ /index.html;
# Add no-cache headers
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache"; # HTTP 1.0 header for backward compatibility
add_header Expires 0;
}
error_page 404 /404.html;
location = /404.html {
internal;
}
# Optionally, handle 404 errors by redirecting to index.html
error_page 404 =200 /index.html;
}