简体   繁体   中英

kubernetes nginx-ingress always redirecting to 404 default backen ignoring path rules

After setting TLS succesfully, i'm not able to reach my web application through the ingress, since it is always redirecting to 404 default backend

This is my ingress configuration:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    kubernetes.io/ingress.class: nginx
    certmanager.k8s.io/cluster-issuer: 'letsencrypt-prod'
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
spec:
  tls:
    - hosts:
        - xxxx.com
        - www.xxxx.com
      secretName: xxxx-com
  rules:
    - host: xxxx.com
    - http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000
    - host: www.xxxx.com
    - http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000

Removing TLS options make it work fine (thought is not using TLS anymore):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000

Nevermid, after many hours i found that my configuration has an error:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    kubernetes.io/ingress.class: nginx
    certmanager.k8s.io/cluster-issuer: 'letsencrypt-prod'
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
spec:
  tls:
    - hosts:
        - xxxx.com
        - www.xxxx.com
      secretName: xxxx-com
  rules:
    - host: xxxx.com
      http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000
    - host: www.xxxx.com
      http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000

Hypens should be removed before http in each host block

That was... hard to find, a warning message when applying a possible weird/wrong configuration would not have hurt anyone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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