From d0955d1b43a5a0149f93a33452c94636cef07e6a Mon Sep 17 00:00:00 2001 From: rev111 <53660903+rev111@users.noreply.github.com> Date: Sun, 1 Jun 2025 21:12:17 +0200 Subject: [PATCH 1/2] Update reverse-proxies.rst Corrected reverse proxying subdirectories with Caddy. Former description would not strip the subdirectory from the reverse proxy target. Changed documentation accordingly. Added an additional paragraph how stripping the subdirectory should be configured in Caddys configuration file. Source: Spent an afternoon figuring this out after unsuccesful application of this doc to a CouchDB+Caddy setup. --- .../src/best-practices/reverse-proxies.rst | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/docs/src/best-practices/reverse-proxies.rst b/src/docs/src/best-practices/reverse-proxies.rst index adb7df0c9e5..19cc275cab1 100644 --- a/src/docs/src/best-practices/reverse-proxies.rst +++ b/src/docs/src/best-practices/reverse-proxies.rst @@ -209,9 +209,9 @@ Reverse proxying CouchDB in a subdirectory with Caddy 2 It can be useful to provide CouchDB as a subdirectory of your overall domain, especially to avoid CORS concerns. Here's an excerpt of a basic Caddy configuration that proxies the URL ``http(s)://domain.com/couchdb`` to -``http://localhost:5984`` so that requests appended to the subdirectory, such +``http://localhost:5984/couchdb`` so that requests appended to the subdirectory, such as ``http(s)://domain.com/couchdb/db1/doc1`` are proxied to -``http://localhost:5984/db1/doc1``. +``http://localhost:5984/couchdb/db1/doc1``. .. code-block:: text @@ -221,6 +221,24 @@ as ``http(s)://domain.com/couchdb/db1/doc1`` are proxied to } +To proxy the URL ``http(s)://domain.com/couchdb`` to +``http://localhost:5984`` so that requests appended to the subdirectory, such +as ``http(s)://domain.com/couchdb/db1/doc1`` are proxied to +``http://localhost:5984/db1/doc1``, you have to configure a route in Caddy: + +.. code-block:: text + + domain.com { + + route /couchdb/* { + uri strip_prefix /couchdb + reverse_proxy localhost:5984 + } + + } + + + Reverse proxying + load balancing for CouchDB clusters ------------------------------------------------------ From ee3b714232634cf5d40beb1d549570d785ef2aad Mon Sep 17 00:00:00 2001 From: rev111 <53660903+rev111@users.noreply.github.com> Date: Mon, 2 Jun 2025 19:39:46 +0200 Subject: [PATCH 2/2] Update reverse-proxies.rst Removed empty lines as requested. Added a short description of the "uri strip_prefix" directive. --- src/docs/src/best-practices/reverse-proxies.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/docs/src/best-practices/reverse-proxies.rst b/src/docs/src/best-practices/reverse-proxies.rst index 19cc275cab1..868f045a3d0 100644 --- a/src/docs/src/best-practices/reverse-proxies.rst +++ b/src/docs/src/best-practices/reverse-proxies.rst @@ -224,7 +224,7 @@ as ``http(s)://domain.com/couchdb/db1/doc1`` are proxied to To proxy the URL ``http(s)://domain.com/couchdb`` to ``http://localhost:5984`` so that requests appended to the subdirectory, such as ``http(s)://domain.com/couchdb/db1/doc1`` are proxied to -``http://localhost:5984/db1/doc1``, you have to configure a route in Caddy: +``http://localhost:5984/db1/doc1``, you have to configure a route in Caddy and strip the subdirectory from the target URI with ``uri strip_prefix``: .. code-block:: text @@ -237,8 +237,6 @@ as ``http(s)://domain.com/couchdb/db1/doc1`` are proxied to } - - Reverse proxying + load balancing for CouchDB clusters ------------------------------------------------------