nginx反向代理打印日志_nginx:当使用nginx作为反向代理时,是否可能捕获访问日志中的响应头?...

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!

解决方案

$http_x_uuid is header sent by client.

Response header send by upstream is $upstream_http_x_uuid

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值