1

I have SPA made with Vue.js.

I handle 404 at client side this way:

//at the end of router
{
  path: '/404',
  name: 'not-found',
  component: () => import(...)
},
{
  path: '*',
  redirect: '/404'
}

Problem: when I'm trying to access some unexisting page on my dev environment, I got nginx default 404 page instead my Vue page.

Parts of Nginx config:

server {
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    //ssl config managed by Certbot
}

server {
    if ($host = <...>) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name <...>;
    listen 80;
}
server {
    if ($host = <...>) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name <...>;
    listen 80;
    return 404; # managed by Certbot
}

Locally I don't have such problems, my local config also has try_files $uri =404; row. What's wrong?

I've tried

location / {
    try_files $uri =404;
}

instead

location / {
    try_files $uri $uri/ =404;
}

, didn't helped.

2 Answers 2

1

Changed try_files $uri $uri/ =404; to try_files $uri $uri/ /index.html;.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

server{    
 error_page 404 $scheme://$host/404;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.