nginx to always serve the root index.html in every path

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



nginx to always serve the root index.html in every path



I have currently the code below. I am wondering if it's possible to still service this root even though I go to other pages like http://localhost/dog. The problem with my command below is it will return 404


server
listen 80;
server_name localhost;

location /
root /usr/src/app/angularjs/dist;





1 Answer
1



It is possible. Add the try_files directive to your location block, this will tell nginx to load all requests that cannot be matched to a filesystem path with your index.html:


try_files


location


index.html



try_files $uri /index.html;


try_files $uri /index.html;






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard