502 Bad Gateway with nginx + apache + subversion + ssl (SVN COPY)

I faced this exact problem today.

Adding the following in the apache2 configuration fixed it:

RequestHeader edit Destination ^https http early

Cheers,
  Ignace M


Source:

  • https://secure.bonkabonka.com/blog/2008/01/04/nginx_fronting_for_subversion.htm

The previous solutions did not work for me, I had to change the nginx configuration and add the following in the location block, before the proxy_pass directive:

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

I found out that the cause of my problem was not the proxy between nginx and apache, but rather was an issue with Apache itself.

What I didn't mention in the original question was what was in the # Some config omitted. This block contained the following:

AuthType Basic
AuthName "Redmine SVN Repository"
Require valid-user
PerlAccessHandler Apache::Authn::Redmine::access_handler
PerlAuthenHandler Apache::Authn::Redmine::authen_handler

For suberversion, I'm controlling user access using Redmine's authentication handler. After turning options on and off and narrowing down the problem, I learned that their authentication module is not thread-safe. I was running into the error because Apache was using the Worker MPM. Switching to the Prefork MPM (sudo aptitude install apache2-mpm-prefork in Ubuntu) resolved the issue.