如何在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

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...