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

**URL:** <https://www.ruby-forum.com/t/is-it-possible-to-capture-response-headers-in-access-log-when-using-nginx-as-a-reverse-proxy/199613>\
**Category:** NGINX\
**Created:** [November 25, 2010, 1:19am UTC](https://www.ruby-forum.com/t/is-it-possible-to-capture-response-headers-in-access-log-when-using-nginx-as-a-reverse-proxy/199613 "2010-11-25T01:19:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 25, 2010, 1:19am UTC](https://www.ruby-forum.com/t/is-it-possible-to-capture-response-headers-in-access-log-when-using-nginx-as-a-reverse-proxy/199613/1 "2010-11-25T01:19:28Z")

</div>

Below is a question I originally posted on Stack Overflow. Feel free to  
respond there if you use that site:

> <https://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.

Thanks so much!

Posted at Nginx Forum:

> **[Is it possible to capture response headers in access log when using nginx as...](https://forum.nginx.org/read.php?2,153136,153136#msg-153136)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![johndavideriksen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e0b2c6/32.png) [@johndavideriksen](https://www.ruby-forum.com/u/johndavideriksen)\
**Post date:** [November 25, 2010, 12:06pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-capture-response-headers-in-access-log-when-using-nginx-as-a-reverse-proxy/199613/2 "2010-11-25T12:06:51Z")

</div>

Hello!

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

> nginx just fine. Our Clojure app logs activity via log4j. Trouble is, is  
> log\_format lt-custom '$remote\_addr - $remote\_user [$time\_local] ’  
> 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:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

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

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Maxim D.
