Curl to Google Compute load balancer gets error 502

If I twist the POST request with downloading the file to my Google load calculator (LB), I get error 502. If I make the same curl for the working node for LB, it works. If I use a library like PHP Guzzle, it works anyway. If I make a basic GET request on LB, I get the correct answer, but the work log does not confirm receipt of the request, as if LB cached it. What's happening? FYI, google LB newb. Thanks

Edit:

I am using GCE HTTP LB. The Curl command looks like this:

curl http://1.2.3.4 -F "key=value" -F "data=@path/to/file"

This curl command works when using the GCE VM IP address, but is NOT used when using the GCE HTTP LB IP.

+8
curl google-compute-engine load-balancing
source share
2 answers

This line of code fixed this for me:

 curl_setopt($ch, CURLOPT_HTTPHEADER, ['Expect:']); 

Obviously, you need to add an empty Expect: header to all the other headers you submit, but this header is what cURL fixes for use with Google HTTP load downloaders.

More details

The Google Docs HTTP (S) load balancing setup has a note at the bottom bottom in Notes and Limitations , which states that HTTP/1.1 100 Continue responses are not supported.

Apparently, by default, cURL will always set Expect: 100-continue headers when sending a POST request. So, apparently, cURL cannot send POST through the default GCE HTTP load balancer.

On the end user side, you see only 502 responses coming back from Google, which is even more confusing, since the same POST on a server that is not behind the load balancer works fine.

However, the presence of Expect: 100-continue causes the Google load balancer to invoke and abort the request.

On the server side, POST data cannot be analyzed (it does not even arrive on the server, although the Content-Length message is correctly reported). In my case, this led to the server returning 500 Internal Server Error, which GCE LB munges sends back to the user as a 502 Bad Gateway error.

After adding an empty Expect: header Expect: my POST data correctly injects it into my load-balanced virtual machines, they parse and return valid responses, and my client receives 200 instead of 502.

Thanks to this issue that helped shed light on this issue.

+5
source share

Traffic from the load balancer to your instance is not enabled by default. Unfortunately, this is poorly documented, and indeed, when you create a load balancer, this should happen automatically.

Try adding this firewall rule to a network that includes a balancer and virtual machines:

 130.211.0.0/22 tcp:1-5000 Apply to all targets 
+1
source share

All Articles