From 34caf19e20d47df9bf1035960efe52e442cbc38e Mon Sep 17 00:00:00 2001 From: Temirkanov Alikhan Date: Mon, 22 Jun 2026 12:29:24 +0300 Subject: [PATCH] Add a section on reverse-proxying via Nginx --- docs/setup_own_server.md | 100 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/docs/setup_own_server.md b/docs/setup_own_server.md index 40dd20d..6e3bcdc 100644 --- a/docs/setup_own_server.md +++ b/docs/setup_own_server.md @@ -291,3 +291,103 @@ entryPoints: ... ``` + +### Nginx + +When configuring nginx as a reverse-proxy for CouchDB, note the common mistakes: + +1. If fast fetch progress stalls and seems to freeze indefinitely, make sure you disabled `proxy_buffering`: + +```nginx +location / { + proxy_pass http://127.0.0.1:5984; + proxy_buffering off; + ... +} +``` + +2. If you get the "413 Entity too large" error, increase the `client_max_body_size`: + +```nginx +location / { + proxy_pass http://127.0.0.1:5984; + client_max_body_size 50M; # Tweak the value to your needs + ... +} +``` + + +3. If you get the "404 Database not found" error, make sure you placed CouchDB at the root location (recommended): + +```nginx +server { + server_name couchdb.domain.com + + location / { + proxy_pass http://127.0.0.1:5984; + ... + } +} +``` + +It is possible to place CouchDB into the subdirectory, however, the config should be modified respectively: + +```nginx + +server { + server_name domain.com + + location /couchdb { + rewrite ^ $request_uri; + rewrite ^/couchdb/(.*) /$1 break; + + proxy_pass http://127.0.0.1:5984$uri; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + ... + } + location /_session { + proxy_pass http://127.0.0.1:5984/_session; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + ... + } +} +``` + +4. If you added custom HTTP headers in database connection advanced settings, make sure to update both nginx and CouchDB configurations: + +Nginx: +```nginx +location / { + set $pass 1; + + # Example of handling custom HTTP header + if ($http_x_custom_header != 'foo'){ + set $pass 0; + } + + # Important: OPTIONS requests don't carry headers, so they should always be proxied to the CouchDB + if ($request_method = 'OPTIONS') { + set $pass 1; + } + + if ($pass = 0) { + return 403; + } + + proxy_pass http://127.0.0.1:5984; + ... +} +``` + +couchdb-etc/docker.ini: +```ini +... +[cors] +credentials = true +origins = app://obsidian.md,capacitor://localhost,http://localhost + +;Make sure to add your custom header to the list so CORS won't break +headers = accept, authorization, content-type, origin, referer, x-custom-header +```