Nginx anti-Leech configuration in CentOS

Source: Internet
Author: User
Judging the Referer of a request can effectively prevent leeching. This function can be implemented using the HTTPReferer module of nginx. when the Referer field in a request header contains some incorrect fields, this module can prohibit this request from accessing the site. This header can be forged at will. Therefore, using this module cannot block these requests 100%. The vast majority of rejected requests come from some typical browsers, it can be considered that these typical browsers do not provide a "Referer"

Determining the Referer of a request can effectively prevent leeching. This function can be implemented using the corresponding HTTP Referer module of nginx.
When the Referer field in a request header contains some incorrect fields, this module can prohibit this request from accessing the site.
This header can be forged at will. Therefore, using this module cannot block these requests 100%. The vast majority of rejected requests come from some typical browsers, it can be considered that these typical browsers do not provide a "Referer" header, or even the correct requests.
For example:
Location/photos /{


Valid_referers none blocked www.mydomain.com mydomain.com;

If ($ invalid_referer ){
Return 403;
}
}

Here there is only one important command valid_referers:
This command assigns a value to the $ invalid_referer variable based on the referer header. its value is 0 or 1.
You can use this command to implement the anti-Leech function. if there is no Referer header value in the valid_referers list, $ invalid_referer will be set to 1 (refer to the token ).
Parameters can be in the following format:


  • None indicates a nonexistent Referer header.
    Blocked means to disguise the Referer header based on the firewall, for example, "Referer: XXXXXXX ".
    Server_names is a list of one or more servers. after version 0.5.33, you can use the "*" wildcard in the name.


Related Article

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.