Tech folks, I have a simple nginx question of whic...
# tribe
s
Tech folks, I have a simple nginx question of which I could not find a convincing answer on Internet. I have an nginx server forwarding http requests to an upstream server. I simply wish to log these headers forwarded to the upstream server in nginx logs. How can I do it?
w
Try using
$http_headername
in the
log_format
https://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_
s
But isn't that the header received from the client? I want to log the header sent to the server that the nginx is serving to.
w
There doesn't appear to be a method to log that. But if you are passing the client headers to upstream, the above will be the same header. The
Host:
header will most likely change (usually configured manually) when going to upstream
s
I am working on websockets. That means, some headers have to be added explicitly in nginx before forwarding to the server, since websocket is a hop-by-hop protocol. I want to confirm whether these additional headers are indeed being added or not. (Because I am not receiving them on the server, so I am either using an incorrect config file on nginx or the problem is somewhere else. I just want to eliminate the doubt on nginx.)
w
If this is just for debugging, may be you can enable debug and check in the error log. You will have a hard time finding it though if traffic is a lot, esp on a prod setup.