1 kubernetes kubernetes-ingress nginx-ingress
我正在尝试将我的域“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;
}
Run Code Online (Sandbox Code Playgroud)
它没有按预期工作。
为了测试,我尝试了这个
nginx.ingress.kubernetes.io/configuration-snippet: |
if ($host = 'test.example.com' ) {
rewrite ^/(.*)$ https://google.com/$1 permanent;
}
Run Code Online (Sandbox Code Playgroud)
这是工作正常。
我的网站正在处理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
Run Code Online (Sandbox Code Playgroud)
Ingress 有一个注释nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
已经处理了这个:
在某些情况下需要从
www.domain.com
to 重定向,domain.com
反之亦然。要启用此功能,请使用注释nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
注意:对于 HTTPS 到 HTTPS 重定向是强制性的,位于 Ingress 的 TLS 部分的 Secret 中定义的 SSL 证书在证书的通用名称中包含两个 FQDN。
最好使用它而不是对抗/调整configuration-snippet
注释。
归档时间: |
|
查看次数: |
2041 次 |
最近记录: |