NGINX在位置块内重写语法


8

也许是一个愚蠢的问题,但是我似乎找不到很好的文档或示例...

当您使用位置块来过滤传入的请求时,您是从匹配的位置还是从请求的开始进行重写?

一个例子:

location ^~ /category/ {
    rewrite ^/category/paid-search-news/?$ /tag/paid-search permanent; # this,
    rewrite ^paid-search-news/?$ /tag/paid-search permanent; # this,
    rewrite paid-search-news/?$ /tag/paid-search permanent; # or this?
}

Answers:


4

从请求开始。有对文档在这里

location /download/ {
  rewrite  ^(/download/.*)/media/(.*)\..*$  $1/mp3/$2.mp3  break;
  rewrite  ^(/download/.*)/audio/(.*)\..*$  $1/mp3/$2.ra   break;
  return   403;
}

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.