Simple method of anti-Leech protection for LNMP images

Source: Internet
Author: User
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.

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.