Detailed description of Nginx anti-Leech configuration

Source: Internet
Author: User
Tags gz file

I. General anti-Leech protection is as follows:

The code is as follows: Copy code
Location ~ *. (Gif | jpg | png | swf | flv) $ {
Valid_referers none blocked www.111cn.net;
If ($ invalid_referer ){
Rewrite ^/http://www.111cn.net;
# Return 404;
}
}

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.
If {} content means, if the road is not specified to jump to the http://www.111cn.net page, of course, directly return 404 is also possible.


The anti-Leech of Nginx is better. Back up it. This is mainly for image anti-Leech protection, because I generally do not directly provide file downloads on the server.

1. If you do anti-Leech protection for full-site images, at least one additional domain name is required to store the images. This is because anti-Leech protection is not available for images across the entire site.

Modify the/usr/local/nginx/conf/nginx. conf file in this case.

2. Configuring Image anti-Leech protection for a single domain name is recommended for individuals. One is easy to control, and the other is to re-create a domain name on the same server to store the image of the leeching prompt.

Modify the/usr/local/nginx/conf/vhost/your own domain name. conf file in this case.

3. You need to prepare a leeching prompt image and place it on another server or another domain name, for example, the following. I did it myself. Haha, bilingual display?

4、find the following code in the configuration file: location...jpg... and change it accordingly. I will explain it slowly.

The code is as follows: Copy code

Location ~ . *. (Gif | jpg | jpeg | png | bmp | swf) $
{
Expires 30d;
Access_log off;
Valid_referers none blocked * .slyar.com * .jetfond.com * .youdao.com * Region * .google.cn * .google.com * Region * .google.com. sg * Region * image.soso.com bing.com region * Region * region;
If ($ invalid_referer)
{
Rewrite ^/http: // your domain name/slyar_hotlinking.png;
}
}

Expires 30d; // client cache time, irrelevant to leeching

Access_log off; // do not record Image access logs, irrelevant to leeching

Valid_referers none blocked... // allows you to access the image site. blocked supports prefix wildcards. None. If you don't know what HTTP Refer is, you don't know. If you know, none indicates matching access without Refer, in layman's terms, it is directly accessed using a URL. Here I write it to indicate that it is allowed. If you cannot even directly enter the image address to see the image, you can delete this parameter.

The code is as follows: Copy code
Rewrite ^/http: // your domain name/slyar_hotlinking.png;

// The leeching request jumps to an image or page.

5. Save and exit wq.

6. Reload the Nginx configuration file, done

The code is as follows: Copy code

/Etc/init. d/nginx reload


NginxHttpAccessKeyModule implements anti-Leech protection

Install nginx's NginxHttpAccessKeyModule first. The running mode is as follows: for example, my nginxdirectory contains a file.gz file. The corresponding URI is http: // your domain name/nginx/file.gz
If ngx_http_accesskey_module is used, a key value is generated based on the user's IP address. The following link is used to access http: // your domain name/download/file.zip? Key = 23497sdf897. Only the specified keyvalue can be used to download file.gz in the nginxdirectory, so as to avoid leeching.

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.