Reverse proxy for a subdirectory
Here's an excerpt of a basic nginx configuration that proxies the URL "http://domain.com/couchdb" to "http://localhost:5984" so that requests appended to the subdirectory, such as "http://domain.com/couchdb/db1/doc1" are proxied to "http://localhost:5984/db1/doc1".
location /couchdb {
rewrite /couchdb/(.*) /$1 break;
proxy_pass http://localhost:5984;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
rewrite放在location里 break标示就是匹配不再另匹配其他location和rewrite,但是改变了url,然后继续执行prox_pass。但是last标示就会停止匹配同一个location里的下一个rewrite但是它会继续
需找匹配其他location。
Nginx子目录反向代理配置
本文介绍如何使用Nginx配置反向代理,将特定子目录下的请求代理到本地不同端口的服务上。例如,将http://domain.com/couchdb下的请求代理到http://localhost:5984,通过Nginx的rewrite和proxy_pass指令实现路径转换。
2737

被折叠的 条评论
为什么被折叠?



