【问题标题】:GCP HTTP Load Balancer returns 502 error if POST data is large如果 POST 数据很大,GCP HTTP 负载均衡器会返回 502 错误
【发布时间】:2016-10-23 22:26:22
【问题描述】:

我们有一个 API 服务器并且正在使用 HTTP 负载均衡器。我们发现如果 HTTP 请求的数据很大,L7 负载均衡器会返回 502 错误。

我们已经确认它在没有负载均衡器的情况下访问 API 时有效(直接访问 API 服务器。)

这个问题可能是一个类似的问题。 HTTP Load Balancer cuts out part of a large request body

有人说使用 L4 网络负载均衡器是一种可能的解决方案,但由于某些原因我们不想使用它,例如基于 URL 的负载均衡和跨区域的负载均衡。

// Response OK (data size is 1024)
curl -H "Content-Type: application/json" -X POST -d '{"xx": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}' https://xxxxxxxxxxxxxxx.com/xx/xxxxxxxxxxxx/xxxxxxxxx

// Response NG (data size is 1025)
curl -H "Content-Type: application/json" -X POST -d '{"xx": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}' https://xxxxxxxxxxxxxxx.com/xx/xxxxxxxxxxxx/xxxxxxxxx

似乎LB对post数据的大小有一些限制。测试表明限制在 1024 字节左右。


更新1

@chaintng saved me。链接帖子上有人说如果帖子数据超过 1024 字节,curl 会添加 "Expect: 100-continue Header"

// Response NG (data size is 1025. without "Expect: ")
curl -H "Content-Type: application/json" -X POST -d '{"xx": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}' https://xxxxxxxxxxxxxxx.com/xx/xxxxxxxxxxxx/xxxxxxxxx

// Response OK (data size is 1025. with "Expect: ")
curl -H "Expect: " -H "Content-Type: application/json" -X POST -d '{"xx": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}' https://xxxxxxxxxxxxxxx.com/xx/xxxxxxxxxxxx/xxxxxxxxx

【问题讨论】:

  • 您终于找到解决方案了吗?我想我遇到了同样的问题:(

标签: google-app-engine google-cloud-platform google-cloud-http-load-balancer


【解决方案1】:

来自这个问题Curl to Google Compute load balancer gets error 502的参考

这是因为 CURL 在请求大型 POST 正文定义标头为 Expect: 100-continue 时具有默认值

Google L7 负载平衡不支持哪些功能(在本文档中声明 https://cloud.google.com/compute/docs/load-balancing/http/

您所要做的就是在执行 curl 之前通过设置标头来忽略此行为。

例如在 PHP 中 curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']);

【讨论】:

  • 很高兴它修复了。
  • 对于curl 命令行,添加:--header "Expect:"
猜你喜欢
  • 2021-09-18
  • 2018-12-30
  • 2021-08-31
  • 1970-01-01
  • 2017-05-09
  • 1970-01-01
  • 2020-10-28
  • 2021-10-14
  • 2018-04-14
相关资源
最近更新 更多