分别在 docker nginx 和 yum install nginx 两个环境下测试都报错.
在 conf.d 内创建了域名 xxx.com.conf 并在配置中使用了 if 语句,测试通过,reload 后也生效.
但是,当在 conf.d 创建 2.conf ,将 if 语句放在这里.
并在 xxx.com.conf 中 include conf.d/2.conf;
测试均报错
nginx: [emerg] "if" directive is not allowed here in /etc/nginx/conf.d/2.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed
奇怪的是 使用军哥 LNMP.org 安装的环境却成功了.
求教大神是否是什么模块需要编译安装还是说有其他配置?
if 语句就是简单的正则过滤.
if ($request_uri ~* "(aaa|bbb|cdf|223|sasss)") {
return 301 https://xxxx.com$request_uri;
}