Yesterday, I saw a friend in the QQ group asking about how to perform anti-Leech protection in the LNMP environment. for this question, I actually answered the question in the forum. I will share it with me and make a note at the same time. Nginx does not support. htaccess, so it cannot be prevented directly from this aspect. we need to modify the configuration file to solve this problem. First, find the conf file of the domain name that requires anti-Leech protection, path:/usr/local/nginx/conf/vhost/, such as z
Yesterday, I saw a friend in the QQ group asking about how to perform anti-Leech protection in the LNMP environment. for this question, I actually answered the question in the forum. I will share it with me and make a note at the same time.
Nginx does not support. htaccess, so it cannot be prevented directly from this aspect. we need to modify the configuration file to solve this problem.
First, find the conf file of the domain name that requires anti-Leech protection, path:/usr/local/nginx/conf/vhost/, such as zrblog.net. conf
Back up the data first, so that you can overwrite it back without making a mistake. this is a good habit !!!
Find the following parts:
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $
{
Expires 30d;
}
Modify it:
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $
{
Valid_referers none blocked www.zrblog.net zrblog.net;
If ($ invalid_referer ){
Rewrite ^/http://vpsaa.com/404.jpg;
# Return 404;
}
Expires 30d;
}
The above content should be modified according to your personal circumstances. I will give a basic explanation here.
First line gif | jpg | jpeg | png ...... These are the file types you need to prevent leeching. you can add some suffix types;
The third line is the domain name of your website, that is, the domain name that is allowed. if there are multiple domain names, add them with spaces;
The fifth line is to give the image to be viewed by the leeching and return a 404.jpg Image. the source address of this image is external links. Otherwise, what others see is XX.
Save the changes, upload the changes to the original location, and restart lnmp to make the changes take effect.
/Root/lnmp restart
In addition, some friends asked how to prevent data collection. There seems to be no particularly effective method at present. we suggest you study it at the system level, such as the limitations of iptables rules.