amazon-ec2 - 带 https 重定向的 EKS ingress-nginx 和 NLB

标签 amazon-ec2 amazon-eks aws-nlb ingress-nginx

我最近遇到了 nlb 问题,在 lb 上使用带有 https 终止的 nlb 在 EKS 上使用重定向 http=>https 和 ingress-nginx 是一次冒险。

现在,我想将 X-Forwarded header 传递给 pod,但这会破坏 http=>https 重定向,我在 http 请求上得到 400。

在服务上,我尝试把服务放到http或者tcp协议(protocol)上,都是一样的。

向服务添加 service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: "*" header ,在所有目标上激活代理协议(protocol) v2,并激活 use-proxy-protocol: 'true' 在 nginx 的 configmap 中用 308 重定向打破了 http-snippet:

http-snippet: |
    server {
      listen 2443;
      return 308 https://$host$request_uri;
    }

有没有人有办法让它可以使用 nlb 以及所有好的 header 和重定向工作?

编辑 在评论请求添加完整的工作配置

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/version: 0.41.0
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
data:
  http-snippet: |
    server {
      listen 2443 proxy_protocol;
      return 308 https://$host$request_uri;
    }
  proxy-real-ip-cidr: 10.4.0.0/16
  use-forwarded-headers: 'true'
  use-proxy-protocol: 'true'
  compute-full-forwarded-for: 'true'

最佳答案

为了结束我们与@night-gold 的评论讨论,要使 NGINX 接受代理协议(protocol),您必须在 listen 指令中特别提及:

http {
    #...
    server {
        listen 80   proxy_protocol;
        listen 443  ssl proxy_protocol;
        #...
    }
}

查看 NGINX guide了解更多。

关于amazon-ec2 - 带 https 重定向的 EKS ingress-nginx 和 NLB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65613674/

相关文章:

amazon-ec2 - 在k8s 1.9上扩展statefulset的PVC大小

java - Grails 部署 - 最快的部署方式?

hadoop - 无法在Spark集群主节点上将大文件加载到HDFS

amazon-web-services - AWS 从控制台创建监听器 - 所有目标组均呈灰色

amazon-web-services - 是否可以在 AWS 中将网络负载均衡器放在具有私有(private)端点的 API 网关前面?

amazon-web-services - 将亚马逊 AWS Elastic Beanstalk 指向现有 EC2

amazon-web-services - 使用 CloudFormation 时 NodeGroup 未加入 EKS 集群

amazon-web-services - 亚马逊 EKS : Setting up worker nodes on spot instances

kubernetes - 如何跟踪 Kubernetes 集群中的所有日志