【问题标题】:Nginx: log the actual forwarded proxy_pass request URI to upstreamNginx:将实际转发的 proxy_pass 请求 URI 记录到上游
【发布时间】:2020-09-01 21:27:18
【问题描述】:

我有以下 nginx 配置文件:

http {

  log_format upstream_logging '[proxied request] '
                              '$server_name$request_uri -> $upstream_addr';
  
  access_log /dev/stdout upstream_logging;

  server {

    listen 80;
    server_name localhost;
    
    location ~ /test/(.*)/foo {
      proxy_pass http://127.0.0.1:3000/$1;
    }
  }
}

当我击中时:

http://localhost/test/bar/foo

我的实际输出是:

[proxied request] localhost/test/bar/foo -> 127.0.0.1:3000 

虽然我的预期输出是:

[proxied request] localhost/test/bar/foo -> 127.0.0.1:3000/bar

是否有变量或方法可以在日志中生成实际的代理 URI?

【问题讨论】:

  • 我也需要那个!
  • @roeb 那么你可以投票支持#reputationSeeker :)

标签: nginx server nginx-reverse-proxy proxypass server-configuration


【解决方案1】:

如果不是生产环境,您可以在所需的本地地址和端口(而不是真实的)上启动最简单的侦听服务器后测试 nginx 发送的内容:

$ nc -l 127.0.0.1 3000
POST /some/uri HTTP/1.0
Host: 127.0.0.1
Connection: close
Content-Length: 14

some payload

【讨论】:

  • 嗯,这可能是一个有趣的解决方法。 ? 但是当我尝试nc -l 127.0.0.1:3000 时,我得到了nc: getaddrinfo: nodename nor servname provided, or not known (?)
  • 感谢您的报告。抱歉,我在主机和端口之间放置了:,这是一个错误。它们必须仅用空格隔开。现在我更正了答案中的示例。
猜你喜欢
  • 1970-01-01
  • 2020-11-15
  • 2015-03-16
  • 2013-07-16
  • 2013-04-19
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 2022-06-29
相关资源
最近更新 更多