SVN & IIS HTTPS offloading reverse proxy: Fix “Server sent unexpected return value (502 Bad Gateway) in response to COPY request”


Recently, I faced the problem that a SVN server returned the error

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

when trying to commit a SVN copy command. In the special scenario the SVN server is hidden behind a IIS that acts as HTTPS offloading reverse proxy (using URL Rewrite and ARR), i.e. the proxy transforms each HTTPS request into to a HTTP request that is forwarded to the SVN server. The reason for the “502 Bad Gateway” error is explained in detail here. Summarized the reverse proxy rewrites the URLs (from HTTPS to HTTP) but does not change the URI information in the request’s HTTP header Destination. In result the SVN server detects a mismatch between the URI in the Destination header (HTTPS) and the URL of the actual request (HTTP).

The solution is to configure the reverse proxy server in a way that the schema of the URI in the Destination header is changed from HTTPS to HTTP before the request is forwarded to the SVN server. I found various posts about how to handle this problems when using the Apache web server (for example here, here or here) but unfortunately no information about this could be done when using an IIS as reverse proxy.

First, you have to add HTTP_DESTINATION as a (allowed) server variable in the IIS Manager as described here in section “Allowing server variables to be changed”. Next, you can define a new rewrite rule that looks as follows:


  
    
  
  
    
  
  

In detail, the rule above uses a condition to match all requests with a Destination header that starts with https and uses the server variable HTTP_DESTINATION to change URI schema to http.

,

3 responses to “SVN & IIS HTTPS offloading reverse proxy: Fix “Server sent unexpected return value (502 Bad Gateway) in response to COPY request””

Leave a Reply

Your email address will not be published. Required fields are marked *