wfade 发表于 2014-01-16 16:15

nginx 使用location捕获的变量

   想通过location 进行正则匹配,然后将正则匹配到的变量捕获出来,通过捕获的变量进行一个alias路径的重新定位。
   但是发现一个问题,我在nginx上location上获取的变量无法正常得到。只能通过set sss $1;这样,然后再通过使用$sss变量才可以,
   求教一个各位高人,这是什么原因。

wfade 发表于 2014-01-16 16:18

If alias is used inside a location defined with a regular expression then such regular expression should contain captures and alias should refer to these captures (0.7.40), for example:

    location ~ ^/users/(.+\.(?:gif|jpe?g|png))$ {
      alias /data/w3/images/$1;
    }



这个nginx 官网的解释 。很明显是可以的,但是我的却不行 。
    location ~ ^/users/(.+\.(?:gif|jpe?g|png))$ {
      set aa $1;
      alias /data/w3/images/$aa;
    }





我的需要这样写才行,不知道为啥。



http://nginx.org/en/docs/http/ngx_http_core_module.html 官网参照

wfade 发表于 2014-01-16 16:20

坐等求助,。。。
页: [1]
查看完整版本: nginx 使用location捕获的变量