tengine 指定某一组页面 不允许境外访问

目标 : 85521A 这本刊 不允许境外访问
特征: 经过分析 该刊的所有url 均为
http://xxxxx /journal/xxxx.aspx?xxx=85521A&xxxxx
也就是说, 特征为 $args ~ .85521A.
实现方法: geoIP
判断条件1: $args ~
.85521A.
判断条件2:$geoip_country_code != CN
经过测试 nginx 的if 不能 and or 等逻辑操作;并且 nginx if 不能嵌套
因此 采用的方法是 设置一个变量 比如$block,
先赋值给 $block deny
然后判断条件1 真的话 重新赋值 $block 为${flag}un
然后判断条件2 真的话 再重新赋值 $block 为${block}cn
那么 如果2个条件都满足的话 $block 为 denyuncn
只满足其中一个的话 $block 就是 denycn 或者 denyun
最后 判断 如果 $block 为denyuncn 那么就不允许访问
则实现目标

....
location xxxx{
........
set $block 'deny';
if ($args ~ .85521A.* ) {
set $block "${block}un";
}
if ($geoip_country_code != CN){
set $block "${block}cn";
}
if ($block = 'denyuncn'){
add_header Content-Type "text/plain;charset=utf-8";
return 200 "You do not have access this resure in your country ";
}
}
........

本文未阐述如何在tengine中编译geo模块

转载于:https://blog.51cto.com/skybug/2131138

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值