我正在使用nginx作为反向代理,尝试从上游服务器(Apache)的响应中读取自定义头部但没有成功。Apache的响应如下:
HTTP/1.0 200 OK
Date: Fri, 14 Sep 2012 20:18:29 GMT
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.10
Connection: close
Content-Type: application/json; charset=UTF-8
My-custom-header: 1
我想读取My-custom-header的值并在if条件语句中使用:
location / {
// ...
// get My-custom-header value here
// ...
}
这可能吗?
$sent_http_my_custom_header
。参见:http://nginx.org/en/docs/http/ngx_http_core_module.html#var_sent_http_ - Nathan$sent_http_
被替换为$http_
。我现在已经恢复了那个编辑。答案仍然是不正确的。$sent_http_name
是一个客户端响应头,从NGINX发送到客户端。OP正在寻求上游响应头,即从上游服务器返回到NGINX的响应中的条目。两者之间的区别很重要,因为某些标头不会从上游转发到客户端。此外,您不能在if
条件中使用响应标头变量。 - Martijn Pieters