If judgment in nginx achieves multiple judgments

Source: Internet
Author: User

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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.