私の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;
とった:
auth_request_set $myheader $upstream_http_x_costumheader;
add_header costum $myheader;