首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cloudant的NGINX代理

Cloudant的NGINX代理
EN

Stack Overflow用户
提问于 2013-06-14 03:00:27
回答 2查看 655关注 0票数 4

我想通过使用proxy_pass在我的域上运行的NGINX公开一些Cloudant的couchdb特性。到目前为止,我已经解决了一些问题(如下所示),但我被困在授权方面。有谁有什么建议吗?

代码语言:javascript
复制
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,但我总是收到禁止的响应。例如,此请求:

代码语言:javascript
复制
http://mydomain/couchdb/my-cloudant-db

返回

代码语言:javascript
复制
{"error":"forbidden", "reason":"_reader access is required for this request"}

谢谢你的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-06-17 23:59:54

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

将proxy_pass行更改为:

代码语言:javascript
复制
proxy_pass http://myusername.cloudant.com$uri;

现在可以毫无问题地工作了。这不是SSL问题,也不是基本身份验证的问题,也不是其他http头问题,也不是Cloudant的问题。这都与我向其转发请求的URI有关。

票数 5
EN

Stack Overflow用户

发布于 2013-07-10 23:09:18

我遇到了一个错误“没有定义要解析的解析器”。我设法通过添加一个解析器来解决这个问题。例如: resolver 8.8.8.8;

参考:http://www.nginx-discovery.com/2011/05/day-51-proxypass-and-resolver.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17094948

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档