如何在Nginx日志中记录反向代理上游服务器服务请求?

前端之家收集整理的这篇文章主要介绍了如何在Nginx日志中记录反向代理上游服务器服务请求?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我们使用Nginx作为反向代理与此设置:

upstream frontends {
  server 127.0.0.1:8000;
  server 127.0.0.1:8001;
  server 127.0.0.1:8002;
  [...]
}

server {
  location / {
    proxy_pass http://frontends;
    [...]
  }
  [...]
}

作为访问日志的一部分,我想记录服务于请求的上游服务器,在我们的例子中,这意味着关联的本地主机端口.

文档(http://wiki.nginx.org/HttpProxyModule#Variables)中的变量提到$proxy_host和$proxy_port,但在日志中,它们总是以“frontends”和“80”的值结尾.

最佳答案
使用$upstream_addr,你会得到例如127.0.0.1:8000或unix:/home/my_user/www/my_site/tmp/.unicorn.sock
原文链接:https://www.f2er.com/nginx/434630.html

猜你在找的Nginx相关文章