在nginx中记录代理活动

hin*_*r90 36 proxy logging rewrite nginx

我正在使用重写和proxy_pass,我在网站上有一些间歇性的问题我也代理了重写.有没有办法记录代理活动,所以我可以调试这个问题?

小智 58

我不是专家,但在我的nginx.conf中遇到了同样的问题:

log_format upstreamlog '[$time_local] $remote_addr - $remote_user - $server_name to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time';

access_log  /var/log/nginx/access.log upstreamlog;
Run Code Online (Sandbox Code Playgroud)

第一行定义一个新格式,然后告诉access_log使用它

  • @Xeoncross log_format必须在`http {}`部分,但是你可以在`location`块中定义`access_log`指令(参见[context](http://nginx.org/en/docs/http) /ngx_http_log_module.html#access_log)). (3认同)