drupal-with-nginx icon indicating copy to clipboard operation
drupal-with-nginx copied to clipboard

Is it possible to get rid of the if?

Open androos opened this issue 7 years ago • 4 comments

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?

androos avatar Aug 06 '17 12:08 androos

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?

jmtorres avatar Aug 18 '17 02:08 jmtorres

## 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;
}

androos avatar Aug 18 '17 13:08 androos

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).

jmtorres avatar Aug 18 '17 13:08 jmtorres

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.

smhanes15 avatar Apr 18 '18 15:04 smhanes15