负载均衡器后面的nginx $ scheme变量

sve*_*tka 20 nginx amazon-elb

如果nxinx在负载均衡器后面运行,是否可以强制nginx $ scheme值为"https"?

在我的场景中,负载均衡器负责与客户端的https通信,并将请求作为原始http转发给nginx.我知道我可以做这样的事情来检测https

set $my_scheme "http";
if ($http_x_forwarded_proto = "https") {
    set $my_scheme "https";
}  
Run Code Online (Sandbox Code Playgroud)

但我只是好奇是否有类似real_ip_headerIP的功能.

在检测https时,是否还需要更新一些标题?

gmc*_*ton 30

我们的设置与您的设置相同,仅使用map而不是if/set(根据nginx开发人员的建议).

# 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;
}
Run Code Online (Sandbox Code Playgroud)

PS我同意,一个real_scheme模块会很好!