NGINX Proxy for Cloudant

I would like to show some Cloudman couchdb features through NGINX running in my domain using proxy_pass. So far, I have developed several kinks (see below), but I am stuck before resolving. Does anyone have any clues?

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) } 

Using this setting, I can successfully Cloudant proxy, but I always get a denied response. For example, this query:

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

returns

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

Thanks for any help.

+4
source share
2 answers

I found a problem. A harmless looking rewrite rule overwrites $ request_uri as the first line and modifies the $ uri variable as part of the execution of the request. $ request_uri does not change when overwriting. Therefore, when I included this variable in the proxy_pass location, I did not correctly include the edited url with / couchdb / deleted.

Change proxy_pass line to:

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

Now it works without problems. This was not an SSL problem, but a problem with basic authentication, as well as another problem with the HTTP header and a problem with Cloudant. All this was connected with the URI to which I sent my request.

+5
source

I am having a problem with the "no resolver defined to resolve" error. I managed to solve this problem by adding, finally, a resolver. for example: resolver 8.8.8.8;

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

+1
source

Source: https://habr.com/ru/post/1486095/


All Articles