简体   繁体   English

nginx 入口如何处理路由规则?

[英]How does the nginx ingress process the routing rules?

I have the following rules defined in the nginx ingress rules yml:我在 nginx 入口规则 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.我有 3 个服务正在运行。 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.我想要的是流向 my-domain/demo 的流量应该重定向到演示服务,对于 /api 与 api-service 服务相同,其他一切都应该 go 到 ui 服务。 However, this sample above does not work, my-domain.com/demo goes to 404. I do not use the rewrite annotation.但是,上面的这个示例不起作用,my-domain.com/demo 转到 404。我不使用 rewrite 注释。

Any idea what is wrong with the routing?知道路由有什么问题吗?

@GáborVarga you need to check few things. @GáborVarga 你需要检查几件事。

  1. Check the output of command "kubectl get ingress", if you can see the resources.检查命令“kubectl get ingress”的output,如果可以看到资源。
  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: "/"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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