【问题标题】:PouchDB - "Database encountered an unknown error" when trying to connect to CouchDBPouchDB - 尝试连接到 CouchDB 时出现“数据库遇到未知错误”
【发布时间】:2015-02-20 05:56:58
【问题描述】:

我正在尝试设置 pouchDB 同步,但远程连接到 couchDB 时遇到问题...我已按照 these instructions from couchDB 安装在我的 ubunto 服务器上 - 由 laravel forge 管理...虽然这个项目本身没有使用 laravel(只是一个普通的 html 文件)

一切都已正确安装,所有预期响应

如果我跑:curl localhost:5984

我得到:{"couchdb":"Welcome","uuid":"*******************","version":"1.6.1","vendor":{"version":"14.04","name":"Ubuntu"}}

我跑了:npm install -g add-cors-to-couchdbadd-cors-to-couchdb

而且我没有收到任何跨域错误

但是,如果我尝试转到 http://178.xx.xxx.xxx:5984/_utils,它就会挂起?

使用以下代码时:

var localdb = new PouchDB('messages');
var remotedb = new PouchDB('http://178.xx.xx.xx:5984/messages');

localdb.sync(remotedb, {live: true});

我明白了:

Unhandled promise rejection 

Promise 
{
    [[PromiseStatus]]: "rejected", 
    [[PromiseValue]]: o
}
__proto__: Promise
[[PromiseStatus]]: "rejected"
[[PromiseValue]]: o
    error: true
    message: "Database encountered an unknown error"
    name: "unknown_error"
    status: 500

(取自 chrome)

知道为什么我会收到此错误吗?它似乎正在超时......任何想法为什么会这样做?

如果我使用:ssh -L5984:127.0.0.1:5984 forge@178.xx.xx.xx

然后转到http://localhost:5984/_utils/ 它工作正常

将远程地址替换为http://localhost:5984/messages 也会使同步工作

在使用它的同时,我还使用“验证安装”检查了所有内容是否已正确安装,并返回“您的安装看起来不错。是时候放松一下了。”

奇怪!

那么有人知道为什么我不能远程连接到 couchDB 吗?

任何帮助将不胜感激!

谢谢, 戴夫

【问题讨论】:

    标签: ubuntu couchdb pouchdb


    【解决方案1】:

    听起来您需要为您的 CouchDB 修改 local.ini 文件,以允许从更多 IP 进行访问,而不仅仅是 localhost。

    查看您的local.ini 了解此部分:

    [httpd]
    ;port = 5984
    ;bind_address = 127.0.0.1
    

    将其更改为:

    [httpd]
    ;port = 5984
    bind_address = 0.0.0.0
    

    编辑:更简单的解决方案是设置您的 Nginx/Apache 代理以将 http://example.com/couchdb 路由到 localhost:5984。这是我使用的 Nginx 配置:

    location /couchdb {
      rewrite /couchdb(.*) $1 break;
      proxy_pass http://127.0.0.1:5984;
      proxy_redirect off;
      proxy_buffering off;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    } 
    

    【讨论】:

    • 感谢@nlawson 的回复...我已经完成了这个并重新启动了couchdb(也在配置面板中确认)仍然无法正常工作:(
    • 您可能还需要配置对 5984 端口的外部访问。这将取决于您的操作系统是如何设置的。在这些情况下,我总是做的是设置一个 nginx/apache 代理,以便例如example.com/couchdb 代理到 localhost:5984。在 nginx 中,我使用this config
    • 太棒了!非常感谢@nlawson ...您的配置完美运行:) 如果您想用您最后的评论回答这个问题,我会接受它作为答案再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 2014-06-10
    • 1970-01-01
    • 2016-06-21
    • 1970-01-01
    • 2015-05-28
    相关资源
    最近更新 更多