Ingress-nginx主机在服务器段中重定向不起作用

发布于 2025-01-23 06:21:44 字数 394 浏览 2 评论 0原文

我正在进入入口中的通配符子域,需要重定向任何包含www的子域的请求到nonwww ie: www.randomsubdomain.domain.com randomsubdomain.domain.com

由于这个原因,我尝试将服务器片段添加到Ingress中,但没有效果,但我已经测试过测试我的正则表达,这符合我的问题,但我的入口似乎被忽略了:

    nginx.ingress.kubernetes.io/server-snippet: |
        if ($host ~* "^(www\.)([0-9a-z]+\.domain\.com)$") {
          return 301 https://$2$request_uri;
        }

I'm using wildcard subdomain in the ingress and need to redirect any request that contains subdomain with www to non-www i.e.:
www.randomsubdomain.domain.com to randomsubdomain.domain.com

For this reason I tried to add server snippet to the ingress but it has no effect at all, I have tested my regular expression and it fits my problem but seem to be ignored by my ingress:

    nginx.ingress.kubernetes.io/server-snippet: |
        if ($host ~* "^(www\.)([0-9a-z]+\.domain\.com)
quot;) {
          return 301 https://$2$request_uri;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹梦 2025-01-30 06:21:44

为此,您只需要添加:

annotations:
   nginx.ingress.kubernetes.io/from-to-www-redirect: "true"

To achieve that you just need to add:

annotations:
   nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文