Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/nginx/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx x-forwarded-for将openshift路由从http更改为https时丢失的头_Nginx_Http Headers_Openshift - Fatal编程技术网

Nginx x-forwarded-for将openshift路由从http更改为https时丢失的头

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 体

在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
体重: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
时,由于某种原因,标题丢失。我编辑了我的答案