Nginx log proxy_passed custom header
In my location, I set this code:
set $clientapikey "<my client api key>";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://$api_route/$path$is_args$args;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $remote_addr;
proxy_set_header clientapikey $clientapikey;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
I want to log the header sent by proxy_pass to the remote url to see if my key is actually sent to the distant server ($api_route
).
I tried to log:
log_format 'Sent-Headers: "clientapikey: '
'$upstream_http_clientapikey '
'$http_clientapikey" ';
But nor $upstream_http_clientapikey nor $http_clientapikey seems to give me access to the proper sent header.
I think the only thing you can do is to just log $clientapikey
. But that will have a well-known value, so I don’t expect it to be of too much use to you in debugging this issue. In this case, I would double check the API server header format using curl first on the nginx server. My bet would be that the API server is actually expecting the HTTP Auth header.
curl -v -h 'clientapikey: my client api key' -X POST http://apiendpoint
n.b. As an aside, calling the api endpoint with http://
should be discouraged because it would allow anyone to read your client api key.