Nginx:仅允许访问与位置名称匹配的引荐来源

Vin*_*cci 3 http-referer nginx

在nginx中,是否有一种方法允许只有具有与当前位置名称匹配的引用者的客户端访问"位置"?

这是场景:

http://foooooo.com/bar.org/

http://foooooo.com/zeta.net/

等等

我希望bar.org位置的内容仅在引用者为bar.org时可用.zeta.net也是如此

我知道我可以"静态地"执行此操作,但是有很多这些位置,我需要找到一种方法来定义一个"动态"位置.

对不起,我的英语不好.

我这样解决了:

location ~/([a-zA-Z0-9\.\-]*)/* {
    set $match "$1::$http_referer";
    if ($match !~* ^(.+)::http[s]*://[www]*[.]*\1.*$ ) {
        return 403;
    }
}
Run Code Online (Sandbox Code Playgroud)

sra*_*ain 8

location ~ ^/([a-zA-Z0-9\.\-]*)/(.*) {
    if ($http_referer !~ "^$1.*$"){
            return 403;
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 6

location /india/xxxxx.js {
    if ($http_referer !~ "http://domain.xxx/"){
            return 403;
    }
}
Run Code Online (Sandbox Code Playgroud)

我通过轻微的改变解决了我的问题,谢谢