nginx referer限制

nginx referer限制

如果用类似$http_referer来正则判断,然后做处理,类似下面这种是不可行的.

       if ($http_referer ~* "www.baidu.com") {
           rewrite ^/(.*)$ http://www.lishiming.net redirect;
       }

因为压根就没有$http_referer这个变量了.所有变量都在这了.http://nginx.org/en/docs/varindex.html

唯一可以找到跟referer有关系的大概就是$invalid_referer了.他得用法详见http://nginx.org/en/docs/http/ngx_http_referer_module.html

valid_referers none blocked server_names
               *.example.com example.* www.example.org/galleries/
               ~\.google\.;

if ($invalid_referer) {
    return 403;
}

有个例子是上面这样的,配合valid_referer用,设置一些合法的referer,然后剩下的就是$invalid_referer,之后用if 处理就简单很多了.

server_names 有两种表示法,一般的字符串和正则的,看e文就可以咯.简单明了.主要是我怕我翻译的有问题,误人子弟就不好了..

  • arbitrary string
    defines a server name and an optional URI prefix. A server name can have an “*” at the beginning or end. During the checking, the server’s port in the “Referer” field is ignored;
  • regular expression
    the first symbol should be a “~”. It should be noted that an expression will be matched against the text starting after the “http://” or “https://”.
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值