简体   繁体   English

使用 proxy_pass 在 nginx 中出现“请求标头或 Cookie 太大”

[英]“Request Header Or Cookie Too Large” in nginx with proxy_pass

I have a following nginx setup on my server A (internet facing, only relevant parts):我的服务器 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;
  }
}

Now, if I go to /some/location it is served fine with new api upstream.现在,如果我去/some/location它可以很好地与新的 api 上游一起使用。 But with anything else I keep getting "400 Bad Request Request Header Or Cookie Too Large" from nginx.但是对于其他任何事情,我不断从 nginx 收到“400 Bad Request Request Header or Cookie Too Large”。 Even with curl with no cookies and only two short headers.即使卷曲没有饼干和只有两个短标题。 Increasing large_client_header_buffers does not help.增加large_client_header_buffers没有帮助。

The interesting part is that I don't see this request coming to Server B at all, so it gets cut off on Server A. Why?有趣的是,我根本没有看到这个请求到达服务器 B,所以它在服务器 A 上被切断了。为什么? Can it be because of https protocol I'm proxy_passing to?可能是因为我代理传递到的https协议吗?

Also, before setting up Server A everything was going to Server B without any problems.此外,在设置服务器 A 之前,一切都将毫无问题地转到服务器 B。

It turns out there was some mix-up with domain resolving (which I don't really understand), and as a result request to server B were passed to Server A instead.事实证明,域解析存在一些混淆(我不太明白),因此对服务器 B 的请求被传递给了服务器 A。 It kept adding its own IP to X-Forwarded-For header, until it exceeded max size - so the error message was actually correct.它不断将自己的 IP 添加到X-Forwarded-For标头,直到超过最大大小 - 因此错误消息实际上是正确的。

To debug further, I used为了进一步调试,我使用了

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM