Get the App
SLTechnology News&Howtos  ›  Servers  › 

Complete steps for Nginx to configure hotlink protection

Shulou Source: shulou.com Published: 2022-06-02 01:16:51 10月01日 Update

Demand:

Usually sites, will want to make their own website videos and pictures, from being embezzled, after all, video traffic, spend money (tuhao can not consider) ~ ~.

First, go straight to the nginx configuration file first.

Server {listen 80th serverSecretname www.test.com;root / data/web/;index index.php index.html;access_log / data/logs/nginx/biao.madacode.access.log main;location / {root / home/data/;} error_page 404 / usr/local/nginx/html/404.html;location ~. *\. (wma | wmv | asf | mp3 | mp4 | zip | rar | jpg | png | swf | flv) ${valid_referers none blocked server_names *. Test.com http://IP;if ($invalid_referer) {return 403;} expires 24h accessory log off } location ~ /\. {deny all;}}

Second, explanation of hotlink protection core configuration file

Location ~. *\. (wma | wmv | asf | mp3 | mp4 | mmf | zip | rar | jpg | gif | png | swf | flv) ${valid_referers none blocked server_names * .test.com http://IP;if ($invalid_referer) {return 403;} expires 24hitaccessory log off;}

Vaild_referers valid reference connection, as follows, otherwise enter $invaild_refere and return 403 forbiden.

1 、 none

If the header of the "Referer" source is empty

2 、 blocked

The "Referer" source header is not empty, but the values are deleted by the proxy or firewall, none of which starts with http:// or https://.

3 、 server_names

The "Referer" source header contains the current server_names (current domain name)

Third, simulated case test

1. Add-- referer simulation reference to see the result directly. Prove that the above configuration is OK.

[root@test] # curl-- referer http://baidu.com-I http://www.test.com/temp/T19254/20190820/video_out_out/1/0011.mp4HTTP/1.1 403 ForbiddenServer: TengineDate: Wed, 21 Aug 2019 09:54:44 GMTContent-Type: text/htmlContent-Length: 639Connection: keep-alive

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support.

Tags: Configuration header source content file video learning anti-theft effective straight in no value single knife picture tuhao domain name that is beginning situation core Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Linux MariaDB Shulou Technology