The first is pseudocode (not supported by nginx). It is written here for convenience:
The code is as follows: |
Copy code |
If ($ remote_addr ~ "^ (12.34 | 56.78)" & $ http_user_agent ~ * "Spider "){ Return 403; } |
This is equivalent and actually available configuration
The code is as follows: |
Copy code |
Set $ flag 0; If ($ remote_addr ~ "^ (12.34 | 56.78 )"){ Set $ flag "$ {flag} 1 "; } If ($ http_user_agent ~ * "Spider "){ Set $ flag "$ {flag} 2 "; } If ($ flag = "012 "){ Return 403; } |
Example 2
The code is as follows: |
Copy code |
If ($ request_uri ~ "Xxx. php? Xxx "){ Set $ iftmp Y; } If ($ http_user_agent ~ "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1 )"){ Set $ iftmp "$ {iftmp} Y "; } If ($ iftmp = YY) {return 400 ;} Location /{ Proxy_pass https: // 172.0.0.11; } |
Focus on setting $ iftmp Y to set iftmp to Y. The set command is a big highlight.
Focus 2: set $ iftmp "$ {iftmp} Y" in set, $ {iftmp} Y overlays the parameters once. $ {iftmp} is a big highlight.
$ Request_uri is the complete request path of the client request, and $ http_user_agent is the browser parameter that the client sends the request.
The above if judgment is a prototype of simple anti-cc attack. Generally, common cc attacks will fix attack pages, and then the browser parameters remain mostly unchanged, if the two if parameters meet both conditions, the third if parameter will be returned to the request side directly with the 400 error,