NGINX は応答からカスタムヘッダーを読み取ることができません。

NGINX は応答からカスタムヘッダーを読み取ることができません。

私の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; 

おすすめ記事