我想通过使用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"}谢谢你的帮助。
发布于 2013-06-17 23:59:54
我找到问题了。看似无害的重写规则作为第一行重写$request_uri并更改$uri变量,作为请求实现的一部分。重写不会更改$request_uri。因此,当我将该变量包含在proxy_pass位置时,我没有正确地包含已编辑的url和删除的/couchdb/。
将proxy_pass行更改为:
proxy_pass http://myusername.cloudant.com$uri;现在可以毫无问题地工作了。这不是SSL问题,也不是基本身份验证的问题,也不是其他http头问题,也不是Cloudant的问题。这都与我向其转发请求的URI有关。
发布于 2013-07-10 23:09:18
我遇到了一个错误“没有定义要解析的解析器”。我设法通过添加一个解析器来解决这个问题。例如: resolver 8.8.8.8;
参考:http://www.nginx-discovery.com/2011/05/day-51-proxypass-and-resolver.html
https://stackoverflow.com/questions/17094948
复制相似问题