: 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
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.