@@ -126,6 +126,8 @@ Go back to the **[Table of Contents](https://github.com/trimstray/nginx-admins-h
126
126
* [ Blocking/allowing IP addresses] ( #blockingallowing-ip-addresses )
127
127
* [ Blocking referrer spam] ( #blocking-referrer-spam )
128
128
* [ Limiting referrer spam] ( #limiting-referrer-spam )
129
+ * [ Blocking User-Agent] ( #blocking-user-agent )
130
+ * [ Limiting User-Agent] ( #limiting-user-agent )
129
131
* [ Limiting the rate of requests with burst mode] ( #limiting-the-rate-of-requests-with-burst-mode )
130
132
* [ Limiting the rate of requests with burst mode and nodelay] ( #limiting-the-rate-of-requests-with-burst-mode-and-nodelay )
131
133
* [ Limiting the rate of requests per IP with geo and map] ( #limiting-the-rate-of-requests-per-ip-with-geo-and-map )
@@ -6527,6 +6529,56 @@ HTTP/1.1 200 1.04 secs: 3174 bytes ==> GET /storage/img/header.jpg
6527
6529
...
6528
6530
` ` `
6529
6531
6532
+ # #### Blocking User-Agent
6533
+
6534
+ Example 1:
6535
+
6536
+ ` ` ` nginx
6537
+ # 1) File: /etc/nginx/limits.conf
6538
+ map $http_user_agent $invalid_ua {
6539
+
6540
+ default 0;
6541
+ " python-requests" 1;
6542
+
6543
+ }
6544
+
6545
+ # 2) Include this file in http context:
6546
+ include /etc/nginx/limits.conf;
6547
+
6548
+ # 3) Turn on in a specific context (e.g. server):
6549
+ server_name example.com;
6550
+
6551
+ if ($invalid_ua ) { return 444; }
6552
+
6553
+ ...
6554
+ ` ` `
6555
+
6556
+ # #### Limiting User-Agent
6557
+
6558
+ Example 1:
6559
+
6560
+ ` ` ` nginx
6561
+ # 1) File: /etc/nginx/limits.conf
6562
+ map $http_user_agent $limit_ip_key_by_ua {
6563
+
6564
+ default " " ;
6565
+ " python-requests" $binary_remote_addr ;
6566
+
6567
+ }
6568
+
6569
+ limit_req_zone $limit_ip_key_by_ua zone=req_for_remote_addr_by_ua:32k rate=10r/m;
6570
+
6571
+ # 2) Include this file in http context:
6572
+ include /etc/nginx/limits.conf;
6573
+
6574
+ # 3) Turn on in a specific context (e.g. server):
6575
+ server_name example.com;
6576
+
6577
+ limit_req zone=req_for_remote_addr_by_ua burst=2;
6578
+
6579
+ ...
6580
+ ` ` `
6581
+
6530
6582
# #### Limiting the rate of requests with burst mode
6531
6583
6532
6584
` ` ` nginx
0 commit comments