简体   繁体   English

服务器片段中的 ingress-nginx 主机重定向不起作用

[英]ingress-nginx host redirect in server snippet doesnt work

I'm using wildcard subdomain in the ingress and need to redirect any request that contains subdomain with www to non-www ie: www.randomsubdomain.domain.com to randomsubdomain.domain.com我在入口处使用通配符子域,需要将任何包含带 www 的子域的请求重定向到非 www,即: www.randomsubdomain.domain.comrandomsubdomain.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)$") {
          return 301 https://$2$request_uri;
        }

To achieve that you just need to add:为此,您只需添加:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM