Skip to content

Instantly share code, notes, and snippets.

@3m1n3nc3
Created July 30, 2023 15:01
Show Gist options
  • Save 3m1n3nc3/aea7b7f9988703a9e809f8ef0da60ff1 to your computer and use it in GitHub Desktop.
Save 3m1n3nc3/aea7b7f9988703a9e809f8ef0da60ff1 to your computer and use it in GitHub Desktop.
SPA hosting tip on Nginx

When hosting an spa on Ngix we often run across one simple bug that keeps our pages out of reach when not accessed from a link on the landing page. And example scenario would be when navigating directly to https://spa-app.com/login without accessing the landing page, we are greated by a 404 Not found error even though we are certain that our content exists.

A rather simple solution to this would be adding the following line before the end of our Nginx Vhost configuration:

server {
  ...
  try_files $uri  $uri/ /index.html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment