Question: Are there some error events / codes that NGINX handles by default?
Background: The following portion of my config stops hotlinking and returns a 403 error.
location ~* \.(jpg|png|svg|webp|ico)$ {
valid_referers none blocked server_names ~\.bing\. ~\.duckduckgo\. ~\.facebook\. ~\.google\. ~\.instagram\. ~\.twitter\. ~\.yahoo\.;
if ($invalid_referer) {
return 403;
}
}
This section blocks unwanted HTTP methods and returns a 405 error.
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 405;
}
This got me thinking, are there any errors that I don't have to set up in NGINX?
For example, a 400 Bad Request error. Does NGINX know what a bad request is without adding an if
statement and some logic to the config?
Alternately do I need to set up every error in the config that I plan to use and if I don't it can't be triggered? I always assumed this was the case but when I see how many different 400 and 500 errors there are I wonder if I'm not fully understanding this concept.
Nginx will handle everything except application level errors. A few examples would be
400 if the request breaks RFC specified format.
403 if nginx cannot read a file due to permission.
404 if the file isn't found.
And so on so forth, the only thing nginx doesn't handle is non-RFC requirements like your anti-hotlinking and things outside its scope such as fastcgi/uwsgi/http backends.
Basically don't worry about anything not related to your specific business logic.