nginx: anti-leech

Anti-leech:
For example: sometimes we reprint an article from a website, such as Tencent, to our own blog or space, and find that some pictures cannot be displayed, which is the effect of anti-leech. The picture is placed on Tencent's server, and Tencent refuses pages from other websites to access the resource.

Under normal circumstances, when we browse a web page, the content of the entire page is not transmitted to the local browser in one request, especially when the page contains pictures or other resources. The first request will return the HTML text of the page, and the browser will parse the text and find that there are still pictures, and will send a second request to obtain pictures. The problem of hotlinking is: if a website does not have the resources mentioned in the page, it will link the picture to other websites, so that the website without any resources uses the resources of other websites to display it to the browser, improving its own However, most browsers will not find it easily, so obviously, it is unfair to the website that has used the resources. Some unscrupulous websites expand their own site content without increasing costs, and often steal links from other websites. On the one hand, it damages the legitimate interests of the original website, on the other hand, it increases the burden on the server
=============================== ===============
location ~* .(gif|jpg|png|swf|flv)$ { 
        valid_referers none blocked *.xxx.com www.abc.com; 
        if ($invalid_referer ) { 
          return 403; 
        } 
}
valid_referers none blocked, where none means an empty source, that is, direct access, such as opening a file directly in the browser, blocked means the source marked by the firewall, *.xxx.com means all subdomains

===== ==========================================
nginx's anti-leech configuration method for file directories :
location /img/ {
  root /data/img/;
  valid_referers none blocked *.xxx.com www.abc.com;
  if ($invalid_referer) {
      rewrite ^/ http://www.xxx.com/error.gif;
  }
}
================================================
NginxHttpAccessKeyModule implementation anti-theft chain

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326268058&siteId=291194637