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。