Welcome! Log In Create A New Profile

Advanced

Re: Is it possible to capture response headers in access log when using nginx as a reverse proxy?

Maxim Dounin
November 25, 2010 06:10AM
Hello!

On Wed, Nov 24, 2010 at 07:17:29PM -0500, johndavideriksen wrote:

> Below is a question I originally posted on Stack Overflow. Feel free to
> respond there if you use that site:
> http://stackoverflow.com/questions/4272686/nginx-is-it-possible-to-capture-response-headers-in-access-log-when-using-nginx
>
> Hi,
>
> We are using nginx as a reverse proxy to control and log access to a
> Clojure (Java) web service application.
>
> We are able to generate an access_log and capture incoming headers using
> nginx just fine. Our Clojure app logs activity via log4j. Trouble is, is
> that we can't match an entry in the access_log to an entry generated by
> the app.
>
> The app responds to access by sending response headers as well as a
> body. We can freely change these response headers. My initial thought
> was to generate a UUID that corresponds to each and every web service
> request and send that back to the user within the reply header X-Uuid.
> My thought was that I could capture this response 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';
>
> It's looking like nginx can capture headers in incoming requests but not
> outgoing replies (I verified this by replacing $http_x_uuid with
> $http_content_type).
>
> So! Is there a way I can tie my access_log enties and my log4j entries
> by capturing outgoing reply headers using nginx? Is there a better way?
> I'd rather not have to rely on users generating their own UUIDs.

Headers returned by upstream server are available via
$upstream_http_* variables, see here:

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

Headers sent to client (these may be different from ones returned
by upstream) are available via $sent_http_* variables, see here:

http://wiki.nginx.org/HttpLogModule#log_format

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Is it possible to capture response headers in access log when using nginx as a reverse proxy?

johndavideriksen November 24, 2010 07:17PM

Re: Is it possible to capture response headers in access log when using nginx as a reverse proxy?

Maxim Dounin November 25, 2010 06:10AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 236
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready