在 Openshift 4.6 中,我部署了一个公开 nginx
服务的应用程序。使用 http
时,我可以在 nginx 日志中看到字段 $http_x_forwarded_for
的 IP。每当我切换到 https
时,$http_x_forwarded_for
header 就会丢失 (-
)。
http
的路由配置:
spec:
host: <my.host.com>
to:
kind: Service
name: my-nginx
weight: 100
port:
targetPort: 80-tcp
wildcardPolicy: None
https
的路由配置:
spec:
host: <my.host.com>
to:
kind: Service
name: my-nginx
weight: 100
port:
targetPort: 443-tcp
tls:
termination: passthrough
wildcardPolicy: None
有没有办法可以保留 https 请求的 http header ?
最佳答案
不在直通
模式下,你不能!
直通意味着 TLS 流量未解密,因此入口 Controller (haproxy) 无法添加或修改 header 字段。
请求转发仅在第 4 层 (tcp) 上完成。
您需要切换到 edge
或 reencrypt
终止模式才能正常工作。
关于nginx - 将 openshift 路由从 http 更改为 https 时 x-forwarded-for header 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66473285/