Cloudant的NGINX代理

Cloudant的NGINX代理,nginx,cloudant,Nginx,Cloudant,我想通过使用proxy_pass在我的域上运行的NGINX公开Cloudant的一些couchdb特性。到目前为止,我已经解决了一些纠结(如下所述),但我被困在授权的范围内。有人有什么建议吗 location /couchdb { rewrite /couchdb/(.*) /$1 break; #chop off start of this url proxy_redirect off proxy_buffering off; proxy_set_head

我想通过使用proxy_pass在我的域上运行的NGINX公开Cloudant的一些couchdb特性。到目前为止,我已经解决了一些纠结(如下所述),但我被困在授权的范围内。有人有什么建议吗

location /couchdb {
    rewrite /couchdb/(.*) /$1 break;   #chop off start of this url

    proxy_redirect off
    proxy_buffering off;
    proxy_set_header Host myusername.cloudant.com;   
    # cannot use $host! must specify my vhost on cloudant

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Authorization "Basic base64-encode(username:password)";

    proxy_pass http://myusername.cloudant.com$request_uri;
    # must use a variable in this url so that the domain is looked up late. 
    # otherwise nginx will fail to start about half the time because of resolver issues
    # (unknown why though)
}
使用此设置,我可以成功地代理到Cloudant,但我总是收到禁止的响应。例如,此请求:

http://mydomain/couchdb/my-cloudant-db
返回

{"error":"forbidden", "reason":"_reader access is required for this request"}

谢谢你的帮助

我发现了这个问题。作为第一行的无害重写规则重写$request_uri,并作为请求实现的一部分更改$uri变量$重写不会更改请求uri。因此,当我将该变量包含在proxy_pass位置时,我没有正确地将/couchdb/remove包含在编辑过的url中

将代理传递行更改为:

proxy_pass http://myusername.cloudant.com$uri;

现在的工作没有问题。这既不是SSL问题,也不是基本身份验证问题,也不是其他http头问题,也不是Cloudant问题。这一切都与我将请求转发到的URI有关

我遇到一个错误“没有定义要解决的解析器”。 我通过添加一个解析器来解决这个问题。e、 g:分解器8.8.8.8


Ref:

您是否自己尝试过base64编码用户名:密码,而不是使用base64编码?我承认我不太擅长nginx向导,但您咨询过吗?@garbados是的,在我的测试nginx.conf中,我的用户名:password base64编码。我确实从你提到的页面的设置开始。。。我对它们进行了一些调整,但无法通过禁止的json错误。我想这可能与Cloudant如何处理我的请求有关。但我不确定,也许我只是错过了其他的头球?