Nginx和CouchDB反向代理不工作

我正在尝试代理[ http:// localhost:5984]到[ http:// localhost / couchdb] 。 我正在运行nginx的代理。 我遵循http://wiki.apache.org/couchdb/Nginx_As_a_Reverse_Proxy中提到的相同的方法,

location /couchdb { rewrite /couchdb/(.*) /$1 break; proxy_pass http://127.0.0.1:5984; 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; } 

但是当我运行curl本地主机/ couchdb我得到以下错误

 {"error":"not_found","reason":"no_db_file"} 

但是,当我运行curl localhost:5984我从couchdb得到了有效的响应。

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

但是当我运行curl本地主机:5984 / couchdb我得到了同样的错误(和日志),我通过反向代理接收。

couchdb日志文件如下所示

 [Fri, 24 Jan 2014 20:41:29 GMT] [debug] [<0.120.0>] 'GET' /couchdb {1,0} from "127.0.0.1" Headers: [{'Accept',"*/*"}, {'Connection',"close"}, {'Host',"localhost"}, {'User-Agent',"curl/7.32.0"}, {'X-Forwarded-For',"127.0.0.1"}, {"X-Real-Ip","127.0.0.1"}] [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, [{file,"couch_httpd_db.erl"},{line,239}]}, {couch_httpd,handle_request_int,5, [{file,"couch_httpd.erl"},{line,332}]}, {mochiweb_http,headers,5, [{file,"mochiweb_http.erl"},{line,94}]}, {proc_lib,init_p_do_apply,3, [{file,"proc_lib.erl"},{line,239}]}] [Fri, 24 Jan 2014 20:41:29 GMT] [info] [<0.120.0>] 127.0.0.1 - - GET /couchdb 404 [Fri, 24 Jan 2014 20:41:29 GMT] [debug] [<0.120.0>] httpd 404 error response: {"error":"not_found","reason":"no_db_file"} 

我相信我的nginxconfiguration是正确的,这就是为什么请求到达couchdb。 如果缺lesscouchdb.couch文件日志说是问题,那么为什么这个数据库不会造成麻烦,当我们直接在端口5984访问它。似乎couchdb mochiweb是令人困惑的东西。

我看到在两个不同的分布上的相同的行为

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

我遇到了同样的问题,你可以通过使用多个捕获组合两个规则:

 rewrite /couch(/)?(.*) /$2 break; 

这是一个适用于查询,查看和复制的configuration:

 location /couchdb/(.*)$ { rewrite /couchdb/(.*) /$1 break; proxy_pass http://127.0.0.1:5984; 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; } 

答案应该是,将proxy_pass http://127.0.0.1:5984更改为proxy_pass http://127.0.0.1:5984/ 。 你是否看到,在proxy_pass url附加一个斜线“/”。 用斜杠,nginx会在“/ couchdb /”之后加上string,而不包含couchdb。 这是一个微妙的伎俩。

我通过添加解决了这个问题

 rewrite /couchdb / break; 

通过localhost / couchdb访问它。 我提到的规则

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

将为localhost / couchdb / db1等工作。