URI setup in Nginx for Next Js export

Viewed 23

I have a static website with Next-Js export, and my Nginx setting is like -

server {
    server_name www.example.com;
    root /var/www/example;
    index index.html index.htm;

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

    listen 80; 
}

This works well but I can not get a 404 error page if we manually update the wrong URL on the client side.

Can anyone explain how to get an error 404 page for not matching URL.

For now, if a manually update URL on the browser, the same page opens which was opened from before.

Thanks

1 Answers

Maybe this help someone - After reading about uri and how Nginx manages order of uri, here is what I came up with :

Ps - I'm still experimenting with this code for now)

server {
    server_name www.example.com;
    root /var/www/example;
    index index.html index.htm;    
      location / {
        try_files $uri.html $uri/ /$uri /404.html;
        # $uri  # /index.html;
      }
    listen 80; 
}
Related