Server sent unexpected return value (502 Bad Gateway) in response to COPY

This was an annoying issue. I initially blamed it on an Apache update and wasted a lot of time going in that direction. When I finally gave up and used Google, I got somewhere.

Thankfully, I wasn’t the only person to run into this and there are at least three different solutions to the problem. Take your pick.

It was explained rather succinctly here:

because nginx pass to backend https:// url in Destination header.
but http:// and https:// urls can not be mixed in COPY request.

In short, the front end speaks https to the client, but it speaks http (non-ssl) to the back end. The header is not changed to reflect this and the COPY command fails.

  1. Rewrite the Destination header via nginx’s rewrite feature:

    set $fixed_destination $http_destination;
    if ( $http_destination ~* ^https(.*)$ )
    {
    set $fixed_destination http$1;
    }

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Destination $fixed_destination;
    proxy_pass http://subversion_hosts;

  2. Have Apache also use SSL (I was using this approach until just recently)
  3. Use mod_headers with Apache.

Fried

I’ve spent the last several weeks testing a new server configuration and finally got some time to implement it. I figured a few hours and I would be done, but I kept running into minor issues that I didn’t uncover or didn’t fully test within my dev environment.

So yeah, it’s now working. nginx isn’t as big a beast as I thought it would be, thanks to a lot of good documentation.

I started with Nginx HTTP Server (packtpub.com) and used a variety of web resources to round out the rest. We’ll see what the world throws against it tomorrow and reconfigure accordingly.