skip to content
Alvin Lucillo

Nginx and Vue Router

/ 1 min read

💻 Tech

try_files $uri $uri/ /index.html;

If you’re hosting your Vue app on nginx server, and you configured your Vue router to use history mode, you’ll need to add this line to your nginx config file. This will allow your Vue app to handle the routing instead of nginx. Without this, if you access a route other than the root route, you’ll get a 404 error. The line above basically tells nginx to serve the index.html file for any route that it doesn’t recognize. The alternative is to list out all the routes in the nginx config file, but that’s not ideal since you already have the routes defined in your Vue app.