26 Jul 2018
nginx的逻辑判断需要注意以下几点:
参考文档:nginx_if语句官方文档
www.abc.com,返回官网www.abc.com?testip=1.2.3.4,并且传入http header:Authorization=authstring,若testip及Authorization两个判断都okay,返回官网www.abc.com?testip=1.2.3.4$arg_testip匹配的就是testip这个参数$tag变量来协助判断underscores_in_headers on;$http_<customized-header-name>(配置里面都要小写,传入的时候可以大写)
server {
...
underscores_in_headers on;
location / {
......
set $tag 1;
if ($request_uri !~* (.*)testip(.*)) {
set $tag 0;
}
if ($arg_testip !~* (1.2.3.4|2.3.4.5|3.4.5.6)) {
set $tag "${tag}1";
}
if ($http_authorization != authstring) {
set $tag "${tag}1";
}
if ($tag = 11) {
return 403;
}
if ($tag = 111) {
return 403;
}
......
}
}