We have an application server that sometimes hangs. We suspect it is due to a bad request from a client.
Can nginx log the complete request/response (like fiddler captures) to files, so we can see the requests that were sent before the hang?
(We probably need to avoid pcap and that approach and do it all in nginx)
If nginx is not the right tool for this, what (other than a network analyzer) might be?
To get the request body sent by visitors, use
client_body_in_file_only on;
and log the "temporary" file it's written to in the logs by appending var$request_body_file
to the log format. "Temporary" files will be located in client_temp directory by default.You can log request headers
$http_<header>
too and sent headers with$sent_http_<header>
.If you have request body and headers you should be able to replay it and get the response your visitor had.
Also something like gor should highly be considered so you could replay the traffic on an other environment where you could let nginx write these temporary files without causing IO issues in production (nginx won't purge them with
on
value that's why It's not that "temporary" in this case).mitmproxy seems to be the right tool to do what you are asking.
The reverse proxy mode would let you capture the request and response just like Fiddler does.
I was looking for an answer to this question, and found this: https://tarunlalwani.com/post/request-capturing-nginx-lua/
Basically, uses a lua script to gather and log all headers:
Then, refer to it from the nginx configuration:
To gather the body, a block is needed in nginx main.conf:
The post linked above details this a lot better.