vue with nginx: path not matching

1.4k views Asked by At

I am setting up vue(2.1.x) with nginx(1.10.2), I have following configuration:

location / {
    root   /var/lib/myRepo/dist/;
    index  index.html;
}

This works when I hit 'http://localhost:8080/', but when I hit other URLs like: 'http://localhost:8080/products/home', I get:

404 Not Found

I also tried following:

root   /var/lib/myRepo/dist/;
location / {
   try_files $uri $uri/ index.html$query_string;
}

What can be wrong here and how to correct this.

1

There are 1 answers

0
user7879355 On

you can follow like this:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        try_files $uri $uri/ @router;
        index index.html;
    }

    location @router {
        rewrite ^.*$ /index.html last;
    }
}