August 2017
Intermediate to advanced
278 pages
8h 53m
English
Before our location block, we add an if statement to compare against the user agent. This ensures it's evaluated for every call. If your intent is to drop the CPU load by blocking malicious requests, it can be a good compromise.
if ($http_user_agent ~ (Baiduspider|Yandex|DirBuster|libwww|"")) {
return 403;
}
The tilde (~) performs a case-sensitive match against the user agent ($http_user_agent), and allows for a partial match. This means that if the user agent string contains Yandex1.0 or Yandex2.0, both will still match the rule.
The list of blocked agents (Baiduspider|Yandex|DirBuster|libwww|""), uses the pipe (|) as an OR so that any of the strings can be matched. The double quotes at the end are there to block any system ...
Read now
Unlock full access