简体   繁体   中英

How does the nginx ingress process the routing rules?

I have the following rules defined in the nginx ingress rules yml:

- host: my-domain.com
    http:
      paths:
        - path: /api
          backend:
            serviceName: api-service
            servicePort: 8080
        - path: /demo
          backend:
            serviceName: demo-service
            servicePort: 4096
        - path: /
          backend:
            serviceName: ui
            servicePort: 80

I have 3 services running. What I want is that the traffic going to my-domain/demo should be redirected to the demo-service, same for /api with the api-service service, and everything else should go to the ui service. However, this sample above does not work, my-domain.com/demo goes to 404. I do not use the rewrite annotation.

Any idea what is wrong with the routing?

@GáborVarga you need to check few things.

  1. Check the output of command "kubectl get ingress", if you can see the resources.
  2. What annotations you are using currently. Below is the list of few example annotations which can be used.
nginx.ingress.kubernetes.io/secure-backends: "false"
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/session-cookie-path: "/"

These annotations are really important

nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/session-cookie-path: "/"

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