drupal-with-nginx
drupal-with-nginx copied to clipboard
Is it possible to get rid of the if?
https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
Nginx and 'if' is evil. I wonder if there is any method to get rid of all the if statements?
The only sections that seem to have if statements are in low traffic admin locations and in the hot linking protection that is not enabled by default. These should not be in the flow for other requests. Are there others that I missed?
## See the blacklist.conf file at the parent dir: /etc/nginx.
## Deny access based on the User-Agent header.
if ($bad_bot) {
return 444;
}
## Deny access based on the Referer header.
if ($bad_referer) {
return 444;
}
## Protection against illegal HTTP methods. Out of the box only HEAD,
## GET and POST are allowed.
if ($not_allowed_method) {
return 405;
}
Those Ifs are not considered evil as they are directly in the server block, only evaluate a mapped variable set in the http block, and only returns an error code or stops processing altogether (444).
More specifically, the first line of the linked resource states: "Directive if has problems when used in location
context...". Emphasis added is mine.
None of the if directives Perusio has setup are within a location block.