I. general anti-leech protection is as follows:
Copy codeThe Code is as follows: location ~ * \. (Gif | jpg | png | swf | flv) $ {
Valid_referers none blocked www.jb51.net jb51.net;
If ($ invalid_referer ){
Rewrite ^/http://www.jb51.net/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 a route is not specified, it will jump to the http://www.jb51.net/retrun.html page. Of course, returning 403directly is also possible.
Ii. Preventing leeching for image Directories
Copy codeThe Code is as follows: location/images /{
Alias/data/images /;
Valid_referers none blocked server_names *. xok. la xok. la;
If ($ invalid_referer) {return 403 ;}
}
Iii. Use the third-party module ngx_http_accesskey_module to implement Nginx anti-leech Protection
The implementation method is as follows:
The implementation method is as follows:
1. Download NginxHttpAccessKeyModule module 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
4. Modify the nginx conf file and add the following lines:
location /download {
accesskey on;
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:
<?
$ipkey= md5("mypass".$_SERVER['REMOTE_ADDR']);
$output_add_key="<a href=http://www.jb51.net/download/G3200507120520LM.rar?key=".$ipkey.">download_add_key</a><br />";
$output_org_url="<a href=http://www.jb51.net/download/G3200507120520LM.rar>download_org_path</a><br />";
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