# NGINX + Subversion + HTTPS and 502 Bad Gateway error

**URL:** <https://www.ruby-forum.com/t/nginx-subversion-https-and-502-bad-gateway-error/155680>\
**Category:** NGINX\
**Created:** [December 15, 2008, 3:40pm UTC](https://www.ruby-forum.com/t/nginx-subversion-https-and-502-bad-gateway-error/155680 "2008-12-15T15:40:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_Gazzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@Mario\_Gazzo](https://www.ruby-forum.com/u/Mario_Gazzo)\
**Post date:** [December 15, 2008, 3:40pm UTC](https://www.ruby-forum.com/t/nginx-subversion-https-and-502-bad-gateway-error/155680/1 "2008-12-15T15:40:03Z")

</div>

Hi,

Could only find one entry about this on the NGINX mailinglist but  
without any answer, so maybe there is someone who can help me with  
this. I get the following svn error when I try to create a branch:

“svn: Server sent unexpected return value (502 Bad Gateway) in  
response to COPY request”

After googling around there was some indications that this could be  
related to running subversion over https behind a reverse proxy  
although I must admit that I am not entirely sure about this. I have a  
subversion server running under Apache with WebDAV and NGINX in front  
as a https reverse proxy. Below you will find an example of my NGINX  
configuration. I am still running version NGINX 0.7.19. Maybe its just  
some configuration stuff missing. Any help would be much appreciated.

Cheers  
Mario

worker\_processes 1;

events {  
worker\_connections 1024;  
}

http {  
include mime.types;  
include proxy.conf;  
default\_type application/octet-stream;

log\_format main '$remote\_addr - $remote\_user [$time\_local] $status ’  
'"$request" $body\_bytes\_sent “$http\_referer” ’  
‘"$http\_user\_agent" “$http\_x\_forwarded\_for”’;

access\_log logs/access.log main;

```
 sendfile on;
 keepalive_timeout 65;

 upstream subversion_hosts {
       server 192.168.1.136:80;
 }

 server {
     listen 443;

ssl on;
ssl_certificate /etc/ssl/certs/mydomain-ssl.crt;
ssl_certificate_key /etc/ssl/private/mydomain-ssl.key;

     server_name www.mydomain.com;

     location /myproj/repos {
       proxy_pass http://subversion_hosts;
     }
 }

```

}

---

<div class="post-metadata">

**Author:** ![Mario\_Gazzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@Mario\_Gazzo](https://www.ruby-forum.com/u/Mario_Gazzo)\
**Post date:** [December 15, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/nginx-subversion-https-and-502-bad-gateway-error/155680/2 "2008-12-15T18:10:39Z")

</div>

On Monday, December 15, 2008 at 16:30:12, Mario Gazzo wrote:

MG\> “svn: Server sent unexpected return value (502 Bad Gateway) in  
MG\> response to COPY request”

MG\> After googling around there was some indications that this could  
MG\> be related to running subversion over https behind a reverse proxy  
MG\> although I must admit that I am not entirely sure about this.

because nginx pass to backend https:// url in Destination header.

but http:// and https:// urls can not be mixed in COPY request.

workaround available:

```
    server_name www.mydomain.com;

    location /myproj/repos {

            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;
    }

```

MG\> server\_name [www.mydomain.com](http://www.mydomain.com);  
MG\> location /myproj/repos {  
MG\> proxy\_pass http://subversion\_hosts;  
MG\> }

---

<div class="post-metadata">

**Author:** ![Mario\_Gazzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@Mario\_Gazzo](https://www.ruby-forum.com/u/Mario_Gazzo)\
**Post date:** [December 15, 2008, 9:32pm UTC](https://www.ruby-forum.com/t/nginx-subversion-https-and-502-bad-gateway-error/155680/3 "2008-12-15T21:32:07Z")

</div>

Hi Gena,

This worked like a charm. Thanks a lot for the quick reply.

Big Ups :))

Mario
