Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to proxy [http://localhost:5984] to [http://localhost/couchdb]. I am running nginx for proxy. I have followed the same method mentioned at,

    location /couchdb {
        rewrite /couchdb/(.*) /$1 break;
        proxy_redirect          off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Real-IP       $remote_addr;

but when I run curl localhost/couchdb I get following error


However when I run curl localhost:5984 I got a valid response from couchdb.

{"couchdb":"Welcome","uuid":"337bb4394efe84536a68a63eee55333f","version":"1.5.0","vendor":    {"name":"The Apache Software Foundation","version":"1.5.0"}}

But when I run curl localhost:5984/couchdb I get the same error (and log) which I am receiving via reverse proxy.

The couchdb log file says following

[Fri, 24 Jan 2014 20:41:29 GMT] [debug] [<0.120.0>] 'GET' /couchdb {1,0} from ""
Headers: [{'Accept',"*/*"},
[Fri, 24 Jan 2014 20:41:29 GMT] [debug] [<0.120.0>] OAuth Params: []
[Fri, 24 Jan 2014 20:41:29 GMT] [error] [<0.1114.0>] Could not open file /var/lib/couchdb/couchdb.couch: no such file or directory
[Fri, 24 Jan 2014 20:41:29 GMT] [debug] [<0.120.0>] Minor error in HTTP request: {not_found,no_db_file}
[Fri, 24 Jan 2014 20:41:29 GMT] [debug] [<0.120.0>] Stacktrace: [{couch_httpd_db,do_db_req,2,
[Fri, 24 Jan 2014 20:41:29 GMT] [info] [<0.120.0>] - - GET /couchdb 404
[Fri, 24 Jan 2014 20:41:29 GMT] [debug] [<0.120.0>] httpd 404 error response:

I believe my nginx configuration is correct thats why request is reaching to couchdb. If the missing couchdb.couch file the log says is problem then why this database is not causing trouble when we access it directly on port 5984. It seems the couchdb mochiweb is confusing something.

I am seeing the same behavior on two different distribution

Ubuntu 10.04: CouchDB V 1.10.0 ArchLinux 3.10: CouchDB V 1.5.0


Ok problem solved. I have to add

rewrite /couchdb / break;

to access it over localhost/couchdb. The rule which I mentioned

rewrite /couchdb/(.*)  /$1 break;

will work for localhost/couchdb/db1 etc.. But now my question is can there be a one rule for both patterns ?

share|improve this question

2 Answers 2

I ran into the same issue, you can combine the two rules by using multiple capturing groups:

rewrite /couch(/)?(.*) /$2 break;
share|improve this answer

Here's a configuration that works well for query, view and replication:

location /couchdb/(.*)$ {
    rewrite /couchdb/(.*) /$1 break;
    proxy_pass_header Accept;
    proxy_pass_header Server;
    keepalive_requests 1000;
    add_header 'Access-Control-Allow-Origin' '*';
    proxy_redirect  off;
    proxy_buffering off;
    proxy_set_header Host $host;
    proxy_set_header Authorization ""; # or according to server.ini
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Real-IP       $remote_addr;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.