负载均衡器后面的nginx $ scheme变量 [英] nginx $scheme variable behind load balancer
问题描述
如果nxinx在负载均衡器后面运行,是否可以将nginx $ scheme 值强制为"https"?
Is it possible to force nginx $scheme value to "https" if nxinx is running behind load balancer?
在我的场景中,负载均衡器负责与客户端进行https通信,并将请求作为原始http转发到nginx.我知道我可以做这样的事情来检测https
In my scenario Load balancer takes care of https communication with client and forwards requests to nginx as raw http. I know I can do something like this to detect https
set $my_scheme "http";
if ($http_x_forwarded_proto = "https") {
set $my_scheme "https";
}
但是我很好奇IP是否有类似real_ip_header
的功能.
but I'm just curious if there is something like real_ip_header
function for IPs.
手动检测https时是否还需要更新一些标头?
Are there also some headers I need to update when detecting https manualy?
推荐答案
我们的设置与您的设置相同,仅使用map
而不是if/set
(由
Our setup is the same as yours, only using map
instead of if/set
(as recommended by the nginx devs).
# Sets a $real_scheme variable whose value is the scheme passed by the load
# balancer in X-Forwarded-Proto (if any), defaulting to $scheme.
# Similar to how the HttpRealIp module treats X-Forwarded-For.
map $http_x_forwarded_proto $real_scheme {
default $http_x_forwarded_proto;
'' $scheme;
}
P.S.我同意,一个real_scheme
模块会很好!
P.S. I agree, a real_scheme
module would be nice!
这篇关于负载均衡器后面的nginx $ scheme变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!