ssl - 升级到 nginx 3.11.1 时获得“最大重定向”
问题描述
我有一个在 AWS 中运行的 Kubernetes 集群,我正在升级各种组件。在内部,我们正在使用 NGINX,它目前在v1.1.1
图表中nginx-ingress
(从旧的 stable提供),具有以下配置:
controller:
publishService:
enabled: "true"
replicaCount: 3
service:
annotations:
external-dns.alpha.kubernetes.io/hostname: '*.MY.TOP.LEVEL.DOMAIN'
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: http
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: [SNIP]
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "443"
targetPorts:
http: http
https: http
我的服务的入口资源看起来像......
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
[SNIP]
spec:
rules:
- host: MY-SERVICE.MY.TOP.LEVEL.DOMAIN
http:
paths:
- backend:
serviceName: MY-SERVICE
servicePort: 80
path: /
status:
loadBalancer:
ingress:
- hostname: [SNIP]
但是,当我升级到图表时,此配置工作得很好v3.11.1
(ingress-nginx
从k8s 博物馆提供)。
使用未修改的配置,卷曲到 HTTPS 方案会重定向回自身:
curl -v https://MY-SERVICE.MY.TOP.LEVEL.DOMAIN/INTERNAL/ROUTE
* Trying W.X.Y.Z...
* TCP_NODELAY set
* Connected to MY-SERVICE.MY.TOP.LEVEL.DOMAIN (W.X.Y.Z) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: CN=*.MY.TOP.LEVEL.DOMAIN
* start date: Aug 21 00:00:00 2020 GMT
* expire date: Sep 20 12:00:00 2021 GMT
* subjectAltName: host "MY-SERVICE.MY.TOP.LEVEL.DOMAIN" matched cert's "*.MY.TOP.LEVEL.DOMAIN"
* issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
* SSL certificate verify ok.
> GET INTERNAL/ROUTE HTTP/1.1
> Host: MY-SERVICE.MY.TOP.LEVEL.DOMAIN
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 308 Permanent Redirect
< Content-Type: text/html
< Date: Wed, 28 Apr 2021 19:07:57 GMT
< Location: https://MY-SERVICE.MY.TOP.LEVEL.DOMAIN/INTERNAL/ROUTE
< Content-Length: 164
< Connection: keep-alive
<
<html>
<head><title>308 Permanent Redirect</title></head>
<body>
<center><h1>308 Permanent Redirect</h1></center>
<hr><center>nginx</center>
</body>
</html>
* Connection #0 to host MY-SERVICE.MY.TOP.LEVEL.DOMAIN left intact
* Closing connection 0
(我希望我已经捕获了更详细的输出......)
我尝试修改 NGINX 配置以附加以下内容:
config:
use-forwarded-headers: "true"
接着...
config:
compute-full-forwarded-for: "true"
use-forwarded-headers: "true"
这些似乎没有什么不同。那是在中午,所以在回滚之前我无法潜入太远。
我应该看什么,我应该如何调试它?
更新:
我希望我已经发布了更新配置的完整副本,因为我会注意到我没有正确地将更改应用到 add config.compute-full-forwarded-for: "true"
。它需要在controller
街区内,我把它放在了别处。
添加配置后compute-full-forwarded-for: "true"
,一切都立即开始工作。
解决方案
这是为更好的可见性而发布的社区 wiki 答案。随意扩展它。
正如@object88 所证实的那样,问题在于config.compute-full-forwarded-for: "true"
位于错误块中的错误配置。将其添加到controller
块中解决了该问题。
推荐阅读
- mysql - 将数据插入到枚举生成的字段mysql时出错
- python - 如何获得每家航空公司的前 5 个理由?
- tensorflow - 在 Keras 中,如何获得预测值和实际值之间差异的平均值
- java - Outlook 365 的 Java OAuth2 身份验证
- apache - 升级 macOS Big Sur 后自制的 httpd 不起作用
- ios - 使用较少的半样板设置 UIView(或对象)的多个属性 - Swift
- javascript - 索引格式错误:int() 以 10 为底的无效文字
- node.js - 如何查询令牌并在云功能内发送推送通知?
- java - Wicket IValidator 的错误消息中的链接是否可能?
- reactjs - Nextjs 项目未编译为 ES5