Nginx x-forwarded-for将openshift路由从http更改为https时丢失的头
在Openshift 4.6中,我部署了一个公开Nginx x-forwarded-for将openshift路由从http更改为https时丢失的头,nginx,http-headers,openshift,Nginx,Http Headers,Openshift,在Openshift 4.6中,我部署了一个公开nginx服务的应用程序。使用http时,我可以在nginx日志中看到$http\u x\u forwarded\u字段的IP。每当我切换到https时,头的$http\u x\u forwarded\u丢失(-) http的路由配置: spec: 主持人: 致: 种类:服务 姓名:我的nginx 体重:100 端口: 目标端口:80 tcp 通配符策略:无 https的路由配置: spec: 主持人: 致: 种类:服务 姓名:我的nginx 体
nginx
服务的应用程序。使用http
时,我可以在nginx日志中看到$http\u x\u forwarded\u字段的IP。每当我切换到https
时,
头的$http\u x\u forwarded\u丢失(-
)
http
的路由配置:
spec:
主持人:
致:
种类:服务
姓名:我的nginx
体重:100
端口:
目标端口:80 tcp
通配符策略:无
https
的路由配置:
spec:
主持人:
致:
种类:服务
姓名:我的nginx
体重:100
端口:
目标端口:443 tcp
tls:
终止:通过
通配符策略:无
有没有一种方法可以保留https请求的http头?是的,因为v4.6应该可以这样做
为此,必须使用httpHeaders.forwardedHeaderPolicy
参数配置入口控制器操作符
但是,当您使用类型为“passthrough”
的路由时,HAProxy不会以任何方式“接触”或修改请求(即解密和/或重新加密)并将其“按原样”路由到端点,因此不会添加或修改“x-forwarded-for”
根据入口控制器上设置的参数,它可与类型为“edge”
或“reencrypt”
的路由一起工作
因此,如果在“passthrough”模式下,你的应用程序没有收到
“x-forwarded-for”
头,那是因为请求上没有这样的头。您的brwoser直接命中OCP入口控制器(即HAProxy),或者OCP前面的负载平衡器未设置此标头转发标头策略似乎没有效果。使用edge
它可以按预期工作。使用passthrough
时,由于某种原因,标题丢失。我编辑了我的答案