Nginx Ingress Controller:主机变量的用途是什么?

Nginx Ingress Controller: What is the purpose of the host variable?

我有这个 nginx 入口控制器:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/use-regex: "true"
    kubernetes.io/ingress.allow-http: "true"
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
    # Limit uploads to 8TB
    nginx.ingress.kubernetes.io/proxy-body-size: 800000m
spec:
  rules:
  - host: myhost.info
    http:
      paths:
      # NOTE: this one should come after all other routes. To avoid hijacking requests.
      - path: /api/walrus(/|$)(.*)
        backend:
          serviceName: service-a
          servicePort: 8080
      - path: /api(/|$)(.*)
        backend:
          serviceName: service-b
          servicePort: 8080
      - path: /(.*)
        backend:
          serviceName: frontend
          servicePort: 8080
  - http:
      paths:
      # NOTE: this one should come after all other routes. To avoid hijacking requests.
      - path: /api/walrus(/|$)(.*)
        backend:
          serviceName: service-a
          servicePort: 8080
      - path: /api(/|$)(.*)
        backend:
          serviceName: service-b
          servicePort: 8080
      - path: /(.*)
        backend:
          serviceName: frontend
          servicePort: 8080

我复制了路径只是为了清楚。我的问题是,添加 host 键与不添加键时的最终结果有何不同?

直到现在我都在使用它,因为如果我没有它,我的 POST 请求会被重定向到 get 请求,如这个问题所示:

但我还注意到,在 EKS 上,如果我确实添加了一个主机,那么所有内容的入口都只是 returns 404,直到我将其删除并仅使用 http 离开。所以我对此有点困惑,希望有人能在这里阐明正确的做事方式。

此外,对于生产环境,如何将主机正确设置为 public 域以及如何设置 tls 证书?

关于 HTTPS:https://aws.amazon.com/blogs/opensource/network-load-balancer-nginx-ingress-controller-eks/#bGA9CAkdlMh has a section "Defining the Ingress resource (with SSL termination) to route traffic to the services created above" that shows how to terminate TLS at nginx-ingress. Even if you're not using an AWS Network Load Balancer (NLB), that may be helpful. In the case of AWS with an NLB, you have another option, terminating at the NLB: https://aws.amazon.com/blogs/aws/new-tls-termination-for-network-load-balancers/

有两个 nginx 入口控制器,不清楚您使用的是哪一个。 nginxinc controller requires a 'host'. The other, https://github.com/kubernetes/ingress-nginx, I'm not sure about. When you use TLS, nginx uses SNI for HTTPS, which seems like it would require a 'host': http://nginx.org/en/docs/http/configuring_https_servers.html#sni