traefik - Traefik unabe to create none www to www redirect
问题描述
I am having trouble to create a none www redirect. I tried examples which worked for others but in my case there is nothing happening. Can anybody help me? I am Using Kubernetes 1.13.5 with traefik:1.7.8-alpine. The Config looks as following.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/redirect-entry-point: https
traefik.ingress.kubernetes.io/redirect-permanent: "true"
traefik.ingress.kubernetes.io/redirect-regex: ^https?://xn--neophytenbekmpfung-wtb.ch/?(.*)
traefik.ingress.kubernetes.io/redirect-replacement: https://www.xn--neophytenbekmpfung-wtb.ch$${1}
traefik.ingress.kubernetes.io/redirect-permanent: "true"
ingress.kubernetes.io/protocol: http
traefik.backend.loadbalancer.sticky: "true"
traefik.ingress.kubernetes.io/affinity: "true"
traefik.ingress.kubernetes.io/session-cookie-name: neophytenbekaempfung-sticky
traefik.ingress.kubernetes.io/error-pages: |-
fives:
status:
- "500-600"
backend: global-default-backend
query: "/500s.html"
fouro3:
status:
- "403"
backend: global-default-backend
query: "/403.html"
fours:
status:
- "400-499"
backend: global-default-backend
query: "/400s.html"
name: neophytenbekaempfung-sitebuilder-ingress
namespace: sitebuilder
spec:
rules:
- host: xn--neophytenbekmpfung-wtb.ch
http:
paths:
- backend:
serviceName: sitebuilder-app-service
servicePort: 80
path: /
- host: www.xn--neophytenbekmpfung-wtb.ch
http:
paths:
- backend:
serviceName: sitebuilder-app-service
servicePort: 80
path: /
Kind regards Gradlon
解决方案
Ok. The reason for the problem is simple. You can not use
traefik.ingress.kubernetes.io/redirect-entry-point: https
traefik.ingress.kubernetes.io/redirect-permanent: "true"
and
traefik.ingress.kubernetes.io/redirect-regex: ^https?://xn--neophytenbekmpfung-wtb.ch/?(.*)
traefik.ingress.kubernetes.io/redirect-replacement: https://www.xn--neophytenbekmpfung-wtb.ch$${1}
traefik.ingress.kubernetes.io/redirect-permanent: "true"
together. The reason for this can be found here: https://github.com/containous/traefik/blob/v1.7/provider/kubernetes/kubernetes.go#L992
The solution for this Particulare case looks like this.
traefik.ingress.kubernetes.io/redirect-regex: ^http://.*?xn--neophytenbekmpfung-wtb.ch/|^https://xn--neophytenbekmpfung-wtb.ch/(.*)
traefik.ingress.kubernetes.io/redirect-replacement: https://www.xn--neophytenbekmpfung-wtb.ch/$1
traefik.ingress.kubernetes.io/redirect-permanent: "true"
I need to make both none www to www but also http to https, with this config I am able to achieve both.
Hope this helps ohters faced with the same problem.
推荐阅读
- kubernetes - 如何为 localhost kubernetes 入口主机创建“DNS 条目”?
- ios - IOS 开发不允许 Speech To 文本颤动,因为它不允许第三方应用程序使用麦克风以及摄像头
- google-analytics-api - 获取原始用户和会话数据
- android - Admob 横幅未与目标 sdk 30 一起显示
- typescript - type '(v1: number, callback: Function) => Promise
' 不能分配给 'string | 类型的参数 ((arguments_0: number) => void)' - android - 您如何为您的 Xamarin Forms 应用程序设置联盟计划?
- excel - 如果 VLOOKUP 结果是正确的值,则连接两个单元格
- python - 将鼠标悬停在 QLabel 中时,如何临时更改链接的颜色?
- node.js - 如何显示猫鼬文档中的密钥数据?
- typescript - 如何编写更好的 TypeScript 类型来解决两个错误