From 64c669d8a7ae6539eff486c81e6e22c47affe104 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 8 Sep 2026 13:53:49 +0200 Subject: [PATCH] docs: improved reverse proxy docs --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9904f6b..ed45652 100644 --- a/README.md +++ b/README.md @@ -270,11 +270,13 @@ location / { proxy_set_header Host $host; proxy_redirect off; - # Ensure COPY and MOVE commands work. Change https://example.com to the - # correct address where the WebDAV server will be deployed at. + # Ensure COPY and MOVE commands work by rewriting the Destination header to + # contain only the path, e.g. /test.txt. Note that the captured group already + # includes the leading slash: adding another one would produce a Destination + # such as //test.txt, which is parsed as a host name and rejected. set $dest $http_destination; - if ($http_destination ~ "^https://example.com(?(.+))") { - set $dest /$path; + if ($http_destination ~ "^https?://[^/]+(?/.*)$") { + set $dest $path; } proxy_set_header Destination $dest; } @@ -299,6 +301,41 @@ example.com { } ``` +#### Serving Under a Subpath + +If the server is not served from the root of the domain, do not strip the subpath in the reverse proxy. The server needs to see it: `PROPFIND` responses contain the full path of each resource, and clients reject the ones that fall outside of the URL they requested. Pass the subpath through and set [`prefix`](#configuration) accordingly, so that the server strips it itself and adds it back to the responses: + +```yaml +prefix: /webdav +``` + +With Caddy, that means using `handle` instead of `handle_path`, as the latter strips the matched prefix before proxying: + +```Caddyfile +example.com { + @hasDest header_regexp dest ^https?://[^/]+(.*)$ + header @hasDest Destination {re.dest.1} + + handle /webdav* { + reverse_proxy 127.0.0.1:6065 { + header_up X-Real-IP {remote_host} + header_up REMOTE-HOST {remote_host} + } + } +} +``` + +With Nginx, use a `location` block for the subpath and keep `proxy_pass` without a trailing path, as a trailing path would replace the prefix: + +```nginx +location /webdav { + proxy_pass http://127.0.0.1:6065; + # ... the remaining headers, as above. +} +``` + +Both the request path and the `Destination` header must carry the prefix. A request without it is answered with `400 Bad Request`. + ## Examples ### Systemd