【问题标题】:"Request Header Or Cookie Too Large" in nginx with proxy_pass带有proxy_pass的nginx中的“请求标头或Cookie太大”
【发布时间】:2018-02-27 22:04:41
【问题描述】:

我的服务器 A 上有以下 nginx 设置(面向互联网,仅相关部分):

upstream new_api {
  server unix:///home/ubuntu/new_api/shared/tmp/sockets/puma.sock;
}

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  large_client_header_buffers 4 16k;

  ssl_certificate           /etc/nginx/cert.crt;
  ssl_certificate_key       /etc/nginx/cert.key;

  location ~ (^(/some/location|/some/other)) {
    proxy_pass http://new_api;
  }

  location / {
    proxy_pass https://serverB.com;
  }
}

现在,如果我转到 /some/location,它可以通过上游的新 api 正常服务。但是我不断从 nginx 收到“400 Bad Request Request Header or Cookie Too Large”。即使 curl 没有 cookie 并且只有两个短标题。增加large_client_header_buffers 没有帮助。

有趣的是,我根本没有看到这个请求到达服务器 B,所以它在服务器 A 上被切断了。为什么?可能是因为https 协议我正在代理传递到吗?

此外,在设置服务器 A 之前,一切都将毫无问题地转到服务器 B。

【问题讨论】:

    标签: nginx cookies http-headers proxypass


    【解决方案1】:

    事实证明,域解析存在一些混淆(我不太明白),结果对服务器 B 的请求被传递给服务器 A。它不断将自己的 IP 添加到 X-Forwarded-For 标头,直到超过最大大小 - 所以错误消息实际上是正确的。

    为了进一步调试,我使用了

    tcpdump -n -S -s 0 -A 'tcp dst port 80' | grep -B3 -A10 "GET"
    

    【讨论】:

    • 我可能遇到了类似的问题,您能否详细说明 tcpdump 命令如何帮助调试?我从中得到输出,但我的 X-Forwarded-For 只显示我转发的实际 IP 一次。
    • 我的问题:X-Forwarded-For: 192.168.100.100, 172.20.0.1, 172.20.0.1, 172.20.0.1, 172.20.0.1, 172.20.0.1, 172.20.0.1, 172.20.0.1, 172.20.0.1, .0.1(重复很多很多次)。我发现了这个运行以下命令:sudo tcpflow -p -c -i any port 8000
    猜你喜欢
    • 1970-01-01
    • 2013-07-05
    • 2018-02-22
    • 2021-07-10
    • 2019-11-09
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多