Three methods for Nginx anti-Leech protection

Source: Internet
Author: User
: This article mainly introduces three methods for Nginx anti-Leech protection. For more information about PHP tutorials, see. I. general anti-Leech protection is as follows:

location ~* \.(gif|jpg|png|swf|flv)$ {   valid_referers none blocked www.jzxue.com jzxue.com;   if ($invalid_referer) {     rewrite ^/ http://www.jzxue.com/retrun.html; #return 403;   } } 

Line 1: gif | jpg | png | swf | flv
Anti-Leech protection is enabled for gif, jpg, png, swf, and flv files.
Row 2: judge the two routes www.ingnix.com.
The content in if {} indicates that if you do not specify a route, you can jump to the http://www.jzxue.com/retrun.html page if you do not specify a route. of course, you can directly return 403.

II. preventing leeching for image directories

location /images/ {   alias /data/images/;   valid_referers none blocked server_names *.xok.la xok.la ;   if ($invalid_referer) {return403;} } 

III. use the third-party module ngx_http_accesskey_module to implement Nginx anti-Leech protection
The implementation method is as follows:
1. download the NginxHttpAccessKeyModule File: http://wiki.nginx.org/File:Nginx-accesskey-2.0.3.tar.gz;
2. unzip the file and find the config file under the nginx-accesskey-2.0.3. Edit this file: replace "$ HTTP_ACCESSKEY_MODULE" with "ngx_http_accesskey_module ";
3. recompile nginx with the following parameters:

./configure --add-module=path/to/nginx-accesskey<
  

Add the original compilation parameters and run: make & make install

  1. Modify the nginx conf file and add the following lines:
location /download { accesskeyon; accesskey_hashmethod md5; accesskey_arg"key"; accesskey_signature"mypass$remote_addr";}

Where:
The accesskey is a module switch;
Accesskey_hashmethod is the MD5 or SHA-1 encryption method;
Accesskey_arg is the keyword parameter in the url;
Accesskey_signature is the encryption value. here it is a string consisting of mypass and access IP.
Access test script download. php:

 download_add_key
";$output_org_url="http://www.jzxue.com/download/G3200507120520LM.rar>download_org_path
";echo$output_add_key;echo$output_org_url;?>

The first download_add_key link can be downloaded normally. The second link download_org_path will return the 403 Forbidden error.
Refer:
NginxHttpAccessKeyModule
Http://xok.la/2009/03/nginx_http_accesskey_module_referer.html

The above describes three methods of Nginx anti-Leech protection, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.