问题:nginx的配置文件中如何写多个条件的if语句?如何写if else
解决:nginx不支持if else,所以只能使用if语句,然后将多条件合并或者使用正则表达式
方法:
set $is_allow_domain '';
if ($host ~* 'xiaomantu.com') {
set $is_allow_domain 1;
}
if ($host ~* 'mantutu.com') {
set $is_allow_domain 1;
}
if ($is_allow_domain != 1) {
return 403;
}
或者
if ($host !~* '[xiaomantu|mantutu].com') { # 好像是错的,不会写
return 403;
}
参考:
https://www.cnblogs.com/songxingzhu/p/6382007.html