nginx模块referer_module防盗链
你的站点是不是图片、视频比较多,本身流量就很大,再有大量的盗链,很容易就把服务器击垮的,所以web站点防盗链很重要的。nginx referer_module 模块可以简单来防止盗链。
模块说明:
This module makes it possible to block access to the site with the incorrect values of line "Referer" in the request header. Keep in mind that it is easy to spoof this header; therefore, the purpose of using of this module consists not in 100% blocking of these requests, but in the blocking of the mass flow of requests, made from typical browsers. Also, consider that the typical browser does not always provide a "Referer" header, even for correct requests. Example location /photos/ { valid_referers none blocked www.mydomain.com mydomain.com; if ($invalid_referer) { return 403; } }
面上设置很简单,匹配 /photos 目录,针对来自 www.mydomain.com mydomain.com 的域名不阻止。如果是无效的 referer 则返回 403 错误,当然你可以 rewrite 到一张图片,或者一个页面。也可以返回 empty_gif
实例:
修改 nginx 的 配置文件 nginx.conf
shell $> vim /usr/local/nginx/conf/nginx.conf
#添加如下
location ~ .*\.(gif|jpg|jpeg|swf|png|flv)$ { valid_referers none blocked www.nginxs.com nginxs.com; if ($invalid_referer) { return 403; } } error_page 403 = /403.jpg; location /403.jpg { empty_gif; }
shell $> /usr/local/nginx/sbin/nginx -s reload
好了,我的nginx blog 对来自 www.ngins.com 和 nginxs.com 域名不防止盗链,如果是别人的站点盗链我的 图片 swf 视频 flv 则会返回 空白。
转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/191.html
一直不明白valid_referers中的blocked参数的作用,请问能帮忙解释下么,谢谢
看单词也知道是 封锁 此路不通的意思啊 ~
不错的博客,能否加个友情链接,贵站的链接已经做好了
以连接·你可以提供你想要连接的 关键词,请你把我站的关键词 改为 nginx 谢谢。
可以实现来路文件验证吗,只允许a.php接收b.js转发过来的地址
@eric
好的,已经改成nginx!
我参照网上许多类似的方法包括您提供的方法,不知道为什么就是不生效。所有图片不管是不是从我自己的网站访问都被屏蔽了。
casino games
online casino
casino games
online slots
online slots