gpt4 book ai didi

kubernetes - 入口将域 www 重写为非 www url

转载 作者:行者123 更新时间:2023-12-05 00:47:06 26 4
gpt4 key购买 nike

我正在尝试将我的域“www.test.example.com”重定向到 test.example.com

在入口我添加了注释

nginx.ingress.kubernetes.io/configuration-snippet: |
if ($host = 'www.test.wotnot.io' ) {
rewrite ^/(.*)$ https://app.test.wotnot.io/$1 permanent;
}

它没有按预期工作。

为了测试我已经尝试过这个

nginx.ingress.kubernetes.io/configuration-snippet: |
if ($host = 'test.example.com' ) {
rewrite ^/(.*)$ https://google.com/$1 permanent;
}

工作正常。

我的网站正在处理 test.example.com 和 ssl 证书。

整个入口

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
certmanager.k8s.io/cluster-issuer: wordpress-staging
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
#nginx.ingress.kubernetes.io/configuration-snippet: |
#if ($host = 'www.test.wotnot.io' ) {
# rewrite ^/(.*)$ https://test.example.io/$1 permanent;
#}
name: wordpress-staging-ingress
spec:
rules:
- host: test.example.io
http:
paths:
- backend:
serviceName: wordpress-site
servicePort: 80
path: /
tls:
- hosts:
- test.example.io
secretName: wordpress-staging

最佳答案

Ingress 有一个注解 nginx.ingress.kubernetes.io/from-to-www-redirect: "true"已经处理了这个:

In some scenarios is required to redirect from www.domain.com to domain.com or vice versa. To enable this feature use the annotation nginx.ingress.kubernetes.io/from-to-www-redirect: "true"

Attention: For HTTPS to HTTPS redirects is mandatory the SSL Certificate defined in the Secret, located in the TLS section of Ingress, contains both FQDN in the common name of the certificate.

你最好使用它而不是对抗/调整 configuration-snippet 注释。

关于kubernetes - 入口将域 www 重写为非 www url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58698185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com