The nuxt project is deployed to nginx, and try_files, is configured in nginx, but the route cannot be redirected.

nuxt project is deployed to nginx , and has been configured in nginx

 location / {
            try_files $uri $uri/ /;
            root   html;
            index  index.html index.htm;
        }

solved the 404 problem caused by routing problems, but only jumped to the home page and did not display anything else depending on the route.

that is, both http://domain/xxx/5af and http://domain/xxx/6bf are displayed on the home page.

other nginx configurations have been tried later

-sharp one
  location / {
            try_files $uri $uri/ /index.html last;
            root   html;
            index  index.html index.htm;
        }
 -sharp two 
   location / {
             try_files $uri $uri/ @router;
             index index.html;
         }

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

all ended in failure.

everything is fine in the locahost environment. So I don"t know where there is something wrong with the nginx configuration, please give me your advice.

as a newcomer to IT, I don"t have a deep understanding of nginx. Thank you very much for your help.

Jul.17,2021

have you solved it yet? I am trapped in the endless cycle of login and home page, and no other routes can access it!


Local and nginx environments access different file directories.

On the

server, the files after build are placed in a directory similar to abc/, and we are accessing these
, so the configuration on nginx should look like this:

  https://router.vuejs.org/zh/g.

Menu