I'm using nginx as a reverse proxy for CouchDB. I'd like to use a prefix for the proxy, e.g. http://[ip]:8080/proxy/testdb
-> http://localhost:5984/testdb
. I'm getting Location:
headers in the HTTP response which are causing my HTTP client to redirect and break. How can I fix my nginx config?
My nginx server block looks like this:
server {
listen 8080;
root /var/www/proxy;
index index.php index.html index.htm;
location /proxy {
rewrite /proxy/(.*) /$1 break;
proxy_pass http://127.0.0.1:5984;
proxy_redirect off;
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Example HTTP response:
HTTP/1.1 201 Created
Server: nginx/1.6.2
Date: Tue, 13 Jan 2015 01:09:00 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 74
Connection: close
Location: http://192.168.0.100/testdb/2134922387
ETag: "1-f355543f12ede9fdc421b4c3ca06c1eb"
Cache-Control: must-revalidate
Based on this, the HTTP client tries to redirect to http://192.168.0.100/testdb/2134922387
, which gives a 404 error. (Uncommenting the two commented config lines didn't seem to change anything).
Example command to produce these headers:
curl -v -X POST -H "Content-Type: application/json" -d "{\"_id\":\"2134922387\",\"test\":\"good\"}" http://192.198.0.100:8080/proxy/testdb
Any ideas on how to fix this Location:
issue?
Edited to add: it looks like changing the proxy_redirect
to proxy_redirect http://$host/ /proxy/;
is helping.
0 Answers