0

I have a private website for personal use only. I have no interest in anyone else accessing my webserver and want nginx to return absolutely nothing on all invalid uri.

How do I purposefully prevent 404 error (or any other errors) from being emitted for invalid uri?

codechimp
  • 1,509
  • 1
  • 14
  • 21
  • What do you mean by ' to return absolutely nothing on all invalid url'. What is 'nothing' on nginx level? – 0stone0 Dec 02 '20 at 15:02

1 Answers1

0

Use try_files with a 'custom' fallback.

Send a 200 status on fallback if the requested file does not exists;

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

try_files $uri $uri/ $uri.html =404;

The last parameter can also be a status code (directly preceded by the equals sign) or the name of a location. In the following example, a 404 error is returned if none of the parameters to the try_files directive resolve to an existing file or directory.

0stone0
  • 34,288
  • 4
  • 39
  • 64