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模块

猜你喜欢

转载自blog.51cto.com/skybug/2131138