Possible nginx documentation error
While trying to get couchdb working from behind nginx on a subdirectory address (x.yz/couchdb), I was following the docs but couldn't get my setup working with the provided steps.
Using the nginx.conf given in the docs, I had 500's because it entered redirect loops. Random changes to the config led to 502's as well as every subsequent subdirectory not working, but I managed with the following:
location /couchdb {
rewrite ^/couchdb/(.*) /$1 break;
proxy_pass http://localhost:5984/;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
}
Changes (compared to the docs) are:
- removal of first rewrite
- replacement of proxy_pass URI with
/
While this (seemingly) works now, I am completely out of my depth when it comes to nginx so I don't even really know why this works and why the "official" config didn't (although I'd like to know and learn). Similarly, I can't even say with certainty that the docs are wrong. I just know they didn't work for me.
So I'm just letting you know that this was my experience and I'll leave it to much smarter people (aka you) to determine whether the docs are wrong or my config is cursed.
Thank you, @crowbait!
I'll ask in the dev chat if anyone is familiar with nginx. I haven't used it in years and completely forgot everything about.
@crowbait We are using it with Nginx for multiple servers and below is a config example from us:
root /var/www/couchssl;
server_name your.url.goes.here;
location /couchdb {
rewrite /couchdb/(.*) /$1 break;
proxy_pass http://localhost:5984/_session;
proxy_redirect off;
proxy_read_timeout 3600;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
}
@idea-christian that fits the docs for session-based replication. The other example in the docs is what I was talking about; that didn't work for me.
@idea-christian I just tried the session-based replication example from the docs (didn't work) and then dropped in your configuration and it does work for me. I see 2 issues:
- you still had to add the
rewritedirective, which isn't mentioned in the docs (and I had to add it too) - it seems like (no data besides my intuition) that the session-based replication isn't that optional.
Consider this wording in the docs:
Session based replication is default functionality since CouchDB 2.3.0. To enable session based replication with reverse proxied CouchDB in a subdirectory.
(Entirely subjective opinion incoming:) to me, this sounds like "yeah, session based replication is on by default, if you want to use it, use this config". Since it's the second entry in this section of the docs, I interpret that as "the first config example is the default, use that one, unless you want SBR". If that's not the case, maybe the wording in the docs could be updated to something like "if you're running CouchDB 2.3.0 or later, you should use this one, because SBR is now the default configuration".
...and still then, the provided configuration didn't work as-is. I'll refer to my original post and reiterate that I have insufficient knowledge of nginx to confidently say that the docs are wrong, but I can confidently say that the docs-example didn't work for me without tweaks.
@nickva I don't know whether the "ping the dev chat" you intended to do resulted in some task or similar, but if so, this might be interesting to add.
Thanks @crowbait and @idea-christian!
Yeah that makes sense for us to update the defaults, the one we have there hasn't bee updated since 2.x days, I think.
@nickva I don't know whether the "ping the dev chat" you intended to do resulted in some task or similar, but if so, this might be interesting to add.
Thanks, I did mention it. The dev chat is just our slack dev channel, there an invite link in https://couchdb.apache.org.