perusio / drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
855 stars 246 forks source link

Is it possible to get rid of the if? #276

Open androos opened 6 years ago

androos commented 6 years ago

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?

jmtorres commented 6 years ago

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?

androos commented 6 years ago
## 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;
}
jmtorres commented 6 years ago

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

smhanes15 commented 6 years ago

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.