![NGINX 无法从响应中读取自定义标头](https://linux22.com/image/161538/NGINX%20%E6%97%A0%E6%B3%95%E4%BB%8E%E5%93%8D%E5%BA%94%E4%B8%AD%E8%AF%BB%E5%8F%96%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A0%87%E5%A4%B4.png)
我想从我的 nginx 服务器获取来自外部 Apache 服务器的带有自定义标头的身份验证响应。问题是,我无法获取自定义标头的值。
location /app {
auth_request /auth;
add_header custom $http_x-customheader;
}
location = /auth {
proxy_pass http://ip.externalserver/auth.php;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Original-METHO $request_method;
proxy_pass_request_headers on;
}
直接向Apache服务器请求时:
$ curl -i "http://xxxx.xxx.xxxx.xxxx/auth.php"
HTTP/1.1 200 OK
Date: Mon, 30 Sep 2019 17:08:05 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.29
x_customheader: 2
x-headername: headervalue
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
Content-Length: 193
Content-Type: text/html
但是通过nginx:
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 30 Sep 2019 16:47:28 GMT
Content-Type: application/vnd.apple.mpegurl
Content-Length: 559
Last-Modified: Mon, 30 Sep 2019 16:47:26 GMT
Connection: keep-alive
ETag: "5d92319e-22f"
Expires: Wed, 08 Jan 2020 16:47:28 GMT
Cache-Control: max-age=8640000
custom: -customheader
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: GET, HEAD, OPTIONS
Access-Control-Allow-Origin: *
Accept-Ranges: bytes
我尝试过这个但没有成功:
add_header custom $http_x-customheader;
add_header custom $http_x_customheader;
add_header custom $upstream_http_x_customheader;
add_header custom $upstream_http_x-customheader;
答案1
知道了:
auth_request_set $myheader $upstream_http_x_costumheader;
add_header costum $myheader;