我正在使用nginx作为反向代理并尝试从上游服务器(Apache)的响应中读取自定义标头,但未成功。 Apache的回应如下:一,如果从句nginx - 从上游服务器读取自定义标头
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
我想从我的定制头读值,并使用它:
location/{
// ...
// get My-custom-header value here
// ...
}
这可能吗?提前致谢。
其实,这是错误的,不应该标记答案。对于将来遇到这个问题的人来说,正确的变量是'$ http_'。以OP为例,'$ http_my_custom_header'(区分大小写!) – jduncanator
我已更正此答案以匹配文档;) –
事实证明,这也不正确。 OP要求读取响应头的值。你应该使用'$ sent_http_my_custom_header'。 http://nginx.org/en/docs/http/ngx_http_core_module.html#var_sent_http_ – Nathan