From eac107aac6b36ed70cbd95a575dfa5e3c3a86377 Mon Sep 17 00:00:00 2001 From: antoine lebaud Date: Thu, 11 Jul 2024 20:15:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20fix=20Nginx=20configur?= =?UTF-8?q?ation=20for=20SPA=20routing=20with=20Vite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/frontend/default.conf | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/frontend/default.conf b/src/frontend/default.conf index fe8f1cb9..f503449c 100644 --- a/src/frontend/default.conf +++ b/src/frontend/default.conf @@ -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; + }