Nginx: Can I capture response headers in the access log when using nginx as a reverse proxy?

We use nginx as a reverse proxy to manage and access the Clojure Log Web Service (Java).

We can generate access_log and capture incoming headers using nginx just fine. Our Clojure app logs activity through log4j. The problem is that we cannot match the entry in access_log with the entry created by the application.

The application responds to access by sending response headers as well as the body. We are free to change these response headers. My initial thought was to generate a UUID corresponding to each web service request and send it back to the user in the X-Uuid response header. My thought was that I could capture this answer by creating a custom log_format :

 log_format lt-custom '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" $request_time $http_x_uuid'; 

This is similar to nginx being able to capture the headers of incoming requests but not outgoing responses (I checked this by replacing $http_x_uuid with $http_content_type ).

So! Is there a way to bind my access_log enties and my access_log entries by capturing the outgoing response headers using nginx? Is there a better way? I would prefer not to rely on users generating their own UUIDs.

Many thanks!

+7
java logging web-services clojure nginx
source share
1 answer

$ http_x_uuid is the header sent by the client. Upstream send response header - $ upstream_http_x_uuid

http://wiki.nginx.org/HttpUpstreamModule#.24upstream_http_.24HEADER

+11
source share

All Articles