我正在使用AWS CloudFront在到达后端之前终止SSL,并且需要将此流量与非CloudFront流量区分开来在Nginx中设置proxy_set_header

我相信执行此操作的最佳方法是检查X-Amz-Cf-Id header (added by CloudFront),并在存在proxy_set_header时对其进行设置。但是,我知道无法在Nginx if语句中设置proxy_set_header,这引发了我的问题。

仅当该 header 存在时,如何设置proxy_set_header值?

最佳答案

一个普遍的答案是,您可以在if中设置变量,然后使用该变量。像这样:

set $variable "";
if ($http_X_Amz_Cf_Id) {
  set $variable "somevalue";
}
proxy_set_header someheader $variable;

关于ssl - Nginx设置proxy_set_header如果头存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40933057/

10-14 22:06
查看更多