iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Nginx怎么配置防盗链
  • 181
分享到

Nginx怎么配置防盗链

2023-06-16 06:06:33 181人浏览 薄情痞子
摘要

这篇文章给大家分享的是有关Nginx怎么配置防盗链的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。一、单刀直入,先上nginx配置文件server {    &nb

这篇文章给大家分享的是有关Nginx怎么配置防盗链的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

一、单刀直入,先上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。

none

"Referer" 来源头部为空的情况

blocked

"Referer"来源头部不为空,但是里面的值被代理或者防火墙删除了,这些值都不以http://或者https://开头.

server_names

"Referer"来源头部包含当前的server_names(当前域名)

三、模拟案例测试

添加 --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怎么配置防盗链

感谢各位的阅读!关于“Nginx怎么配置防盗链”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

--结束END--

本文标题: Nginx怎么配置防盗链

本文链接: https://www.lsjlt.com/news/282652.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作