我想通过使用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变量更改为请求实现的一部分. $request\_uri不会被重写更改.因此,当我在proxy\_pass位置包含该变量时,我没有正确地将已编辑的url包含在/ couchdb / removed中.

将proxy\_pass行更改为:

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

现在没有问题.这不是SSL问题,也不是基本身份验证或其他http头问题的问题,也不是Cloudant的问题.这都与我转发请求的URI有关.

标签: nginx, cloudant

相关文章推荐

添加新评论,含*的栏目为必填