Nginx:只允许访问与位置名称匹配的引荐来源网址 [英] Nginx: allow access only to referrer that match location name
本文介绍了Nginx:只允许访问与位置名称匹配的引荐来源网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在nginx中,是否有一种方法,仅允许具有与当前位置名称匹配的引荐来源网址的客户端访问位置"?
Is there a way, in nginx, to allow access to a "location" only to clients with a referrer that matches the current location name?
这是场景:
等等等
仅当引荐来源网址为bar.org时,我才希望bar.org位置的内容可用. zeta.net也是如此
I want the contents of the bar.org location available only if the referrer is bar.org. The same goes for zeta.net
我知道我可以静态"执行此操作,但是其中很多位置都需要找到一种方法来仅定义一个动态"位置.
I know I can do this "statically", but there are a lot of those locations and I need to find a way to do this defining only one "dynamic" location.
对不起,我的英语不好.
Sorry for my bad english.
解决方案
我已经解决了这种方式:
I've solved this way:
location ~/([a-zA-Z0-9\.\-]*)/* {
set $match "$1::$http_referer";
if ($match !~* ^(.+)::http[s]*://[www]*[.]*\1.*$ ) {
return 403;
}
}
推荐答案
location ~ ^/([a-zA-Z0-9\.\-]*)/(.*) {
if ($http_referer !~ "^$1.*$"){
return 403;
}
}
这篇关于Nginx:只允许访问与位置名称匹配的引荐来源网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文