3

From my nginx server I want to get an auth response with custom headers from an external Apache server. The problem is, I can't get the custom header's value.

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;

}

When directly requesting from the Apache server:

$ 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

but through 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

I have tried this without success:

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; 
2

Got it:

auth_request_set $myheader $upstream_http_x_costumheader;
add_header costum $myheader; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.