Nginx Apache 2 and subversion 502 Bad Gateway error

nginx_logo_2The Problem

I recently ran into this problem and couldn’t find any useful information on the net around fixing it. All subversion checkouts, commits and other basic operations work just fine, but when attempting to copy, move or tag (copy) I would get the below (502 Bad Gateway) error.

Our Setup

We have a machine running nginx on port 80 (and 443 SSL) that serves up a bunch of development tools – buildbots, Jenkins, git repos and of course a few subversion repos. Behind it we have an Apache2 server that serves up subversion repos over WebDAV.

nginx simply reverse proxies requests to the backend Apache 2 servers and handles the SSL termination as our repos are only available over SSL (https).

What’s Really Happening

The actual problem is not really that obvious.

When you perform a remote svn operation like MOVE or COPY the actual request is translated into a WebDAV request that looks similar to this:


Apache, the webserver, translates the above request to:

It uses the Host parameter and the first request line


However, since requests are being reverse proxied through nginx, the source URL is changed from https:// to http:// as Apache listens on port 80 (HTTP). This results in a COPY operation that looks like this:

Note the http:// instead of https://

Apache quickly figures out that it can’t move a file to, because as far as Apache is concerned and are two entirely different hosts.

… and you end up with a “502 Bad Gateway” error.

The Solution

The solution to this problem is getting nginx to change the Destination header in the same way it changes the Host header. Apache can then handle the COPY or MOVE operation correctly. This is done by adding the following to your nginx configuration:

Complete Configs

For reference purposes I’ve included the complete configs below.