跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 求教 nginx 内无法使用 include 调用含有 if 的配置?
未分類
12 6 月 2021

求教 nginx 内无法使用 include 调用含有 if 的配置?

求教 nginx 内无法使用 include 调用含有 if 的配置?

資深大佬 : stille 7

分别在 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;     } 

大佬有話說 (3)

  • 資深大佬 : eason1874

    有 if 可以 include
    你的问题应该是在 nginx.conf 写了 include conf.d/*.conf;
    所以 2.conf 不仅被 xxx.com.conf 载入了,也被 nginx.conf http 载入了,而 http 段是不支持 if 的

  • 主 資深大佬 : stille

    @eason1874 噢,感谢回复,那最佳解决方案是换个目录放这个 2.conf 吧,只要不是 nginx.conf include 的到就行…然后单独给域名.conf include 到就行

  • 主 資深大佬 : stille

    @eason1874 谢谢.测试成功了…

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具