While passing request nginx replaces URI part which corresponds to location with one indicated in proxy_pass directive. But there are two exceptions from this rule when it is not possible to determine what to replace:

if the location is given by regular expression;
if inside proxied location URI is changed by rewrite directive, and this configuration will be used to process request (break):
location  /name/ {
  rewrite      /name/([^/] +)  /users?name=$1  break;
For these cases of URI it is transferred without the mapping.
1.location 标段使用正则表达式
2.执行代理动作的location段内使用了rewrite指令对location URI进行了修改,并且使用rewrite后的配置发出请求(break)。


A special case is using variables in the proxy_pass statement: The requested URL is not used and you are fully responsible to construct the target URL yourself.

This means, the following is not what you want for rewriting into a zope virtual host monster, as it will proxy always to the same URL (within one server specification):


location / {
Instead use a combination of rewrite and proxy_pass:上面的语句要写成下面的:

location / {
  rewrite ^(.*)$ /VirtualHostBase/https/$server_name:443/some/path/VirtualHostRoot$1 break;


rewrite的permanent和redirect重写后的url会在url栏显示,在数据包的层面,添加了location http header
posted @ 2014-02-20 17:35  silence.li  阅读(3357)  评论(0编辑  收藏  举报