无法在nginx中重写url代理

我正在尝试托pipe一个Bower仓库来抛弃一个nginx代理。 但是,我无法find如何正确configuration。 我想从url的开头/bower 。 我目前有以下configuration。

 location /bower { rewrite /bower/(.*) /$1 break; proxy_pass http://localhost:5678; proxy_redirect off; proxy_set_header Host $host; } 

使用这种configuration,当向代理服务器后面的bower仓库发出请求时, /bower部分仍然没有被剥离。

做到这一点:

 location /bower/ { proxy_pass http://localhost:5678/; proxy_redirect off; proxy_set_header Host $host; } 

请注意在位置和proxy_pass上添加的斜杠。 bower后端是否需要proxy_set_header?

编辑:这在nginx文档中描述得相当好