Nginx配置防盗链的完整步骤

fenghuoliuxing0 2019-09-07

éæ±ï¼

é常ç«ç¹ï¼é½ä¼æ³è®©èªå·±ç½ç«çè§é¢åå¾çï¼å被çç¨ï¼æ¯ç«è§é¢æµéï¼è±çé½æ¯ç½è±è±é¶å­ï¼å豪å¯ä»¥ä¸ç¨èèï¼~~.

ä¸ãååç´å¥ï¼åä¸nginxéç½®æ件

server {
listen 80;
server_name 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|mmf|zip|rar|jpg|gif|png|swf|flv)$
{
valid_referers none blocked server_names *.test.com http://IP;
if ($invalid_referer) {
return 403;
}
expires 24h;
access_log off;

}
location ~ /\.
{
deny all;
}

}

äºãé²çé¾æ ¸å¿éç½®æ件解é

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 24h;
access_log off;

}

vaild_referers ææçå¼ç¨è¿æ¥ï¼å¦ä¸ï¼å¦åå°±è¿å¥$invaild_refere,è¿å403 forbidenã

1ãnone

"Referer" æ¥æºå¤´é¨ä¸ºç©ºçæåµ

2ãblocked

"Referer"æ¥æºå¤´é¨ä¸ä¸ºç©ºï¼ä½æ¯éé¢çå¼è¢«ä»£çæèé²ç«å¢å é¤äºï¼è¿äºå¼é½ä¸ä»¥http://æèhttps://å¼å¤´.

3ãserver_names

"Referer"æ¥æºå¤´é¨åå«å½åçserver_namesï¼å½åååï¼

ä¸ã模ææ¡ä¾æµè¯

1ãæ·»å  --referer 模æå¼ç¨ï¼çç»æç´æ¥403.è¯æä¸é¢éç½®æ¯OKç

[root@test]# curl --referer http://baidu.com -I http://www.test.com/temp/T19254/20190820/video_out_out/1/0011.mp4
HTTP/1.1 403 Forbidden
Server: Tengine
Date: Wed, 21 Aug 2019 09:54:44 GMT
Content-Type: text/html
Content-Length: 639
Connection: keep-alive

Nginx配置防盗链的完整步骤

æ»ç»

以ä¸å°±æ¯è¿ç¯æç« çå¨é¨å容äºï¼å¸ææ¬æçå容对大家ç学习æèå·¥ä½å·æä¸å®çåè学习价å¼ï¼è°¢è°¢å¤§å®¶å¯¹èæ¬ä¹å®¶çæ¯æã

相关推荐