Keepass Sync with WebDAV server results in Bad Gateway 502 when using HAProxy

The failing HTTP transaction is this:

MOVE /webdav/Database.kdbx.tmp HTTP/1.1
destination: https://webdav.mydomain.de/webdav/Database.kdbx
authorization: Basic <omitted>
host: webdav.mydomain.de
x-forwarded-proto: https
x-forwarded-for: <omitted>
connection: close

HTTP/1.1 502 Bad Gateway
Date: Tue, 23 Jun 2020 18:13:53 GMT
Server: Apache
Content-Length: 255
Connection: close
Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Bad Gateway</title>
</head><body>
<h1>Bad Gateway</h1>
<p>Destination URI refers to different scheme or port (https://hostname:443)
(want: http://hostname:5005)</p>
</body></html>

As the MOVE request requires a destination header that includes the entire scheme and hostname, it looks like the backend doesn’t like the fact that it’s HTTPS.

You can try modifying https to http in that particular request header:

http-request replace-header destination ^https(.+) http\1

If it still doesn’t work, try replacing the entire hostname with what the backend apparently wants:

http-request replace-header destination https://webdav.mydomain.de/(.+) http://hostname:5005/\1
1 Like