Difference between revisions of "Block particular user agent (bots) in nginx"

From DevOps Notebook
(Created page with "<pre> # case insensitive matching if ($http_user_agent ~* (netcrawl|npbot|malicious|LWP::Simple|BBBike|wget|jorgee)) { return 403; } </pre>")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<pre>
+
Add inside nginx server block
 +
<syntaxhighlight lang="nginx">
 
     # case insensitive matching
 
     # case insensitive matching
     if ($http_user_agent ~* (netcrawl|npbot|malicious|LWP::Simple|BBBike|wget|jorgee)) {
+
     if ($http_user_agent ~* (crawler1|spiderbot|wget|curl)) {
 
         return 403;
 
         return 403;
 
     }
 
     }
</pre>
+
</syntaxhighlight>

Latest revision as of 18:57, 8 October 2020

Add inside nginx server block

    # case insensitive matching
    if ($http_user_agent ~* (crawler1|spiderbot|wget|curl)) {
        return 403;
    }