我使用nginx作为CouchDB的反向代理。 我想为代理使用前缀,例如http://[ip]:8080/proxy/testdb – > http://localhost:5984/testdb 。 我得到了HTTP响应中的Location: headers,它们导致我的HTTP客户端redirect并中断。 我怎样才能修复我的nginxconfiguration?
我的nginx服务器块如下所示:
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; } }
HTTP响应示例:
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
在此基础上,HTTP客户端尝试redirect到http://192.168.0.100/testdb/2134922387 ,这会导致404错误。 (取消注释这两个注释的configuration行似乎没有改变任何东西)。
生成这些头文件的示例命令:
curl -v -X POST -H "Content-Type: application/json" -d "{\"_id\":\"2134922387\",\"test\":\"good\"}" http://192.198.0.100:8080/proxy/testdb
任何想法如何解决这个Location:问题?
编辑添加:它看起来像将proxy_redirect更改为proxy_redirect http://$host/ /proxy/; 正在帮助。