nginx - 将 openshift 路由从 http 更改为 https 时 x-forwarded-for header 丢失

标签 nginx http-headers openshift

在 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) 上完成。
您需要切换到 edgereencrypt 终止模式才能正常工作。

关于nginx - 将 openshift 路由从 http 更改为 https 时 x-forwarded-for header 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66473285/

相关文章:

nginx - CORS 请求中未接受响应状态 201

node.js - 我应该在生产中使用 Nginx 来服务 React 吗?

nginx + uwsgi + debian + 守护进程

c++ - 在 proxygen 中获取 header 值

swift - PFFile 返回不正确的图像 URL

python - Python标准包将HTTP响应码转为文本消息

c# - 如何发送缓存控制 : no-cache in HTTP Response header?

node.js - 无法在 openshift 上运行特定版本的 Node

mysql - 部署 Question2Answer

php - 未设置 Redhat Openshift MySQL 环境变量