验证代码:
server{
listen 80; server_name ; location ~ /test1.txt { rewrite /test1.txt /test2.txt break; #rewrite /test1.txt /test2.txt last; } location ~ /test2.txt { root /var/txt/; }
}
文件设置:
验证rewrite /test1.txt /test2.txt break;在/usr/local/nginx/html 有test2.txt 内容为 /usr/local/nginx/html/test2
验证 rewrite /test1.txt /test2.txt last;在/var/txt/ 有test2.txt 内容为/var/test2
说明:
在使用break时,/test1.txt rewrite 为/test2.txt 不向下边的location中查找,我们会查看到 /usr/local/nginx/html/test2,说明是/usr/local/nginx/html中的test2.txt
(last其实就相当于一个新的url,,对nginx进行了一次请求,需要走一遍大多数的处理过程,最重要的是会做一次find config,提供了一个可以转到其他location的配置中处理的机会,)
(break则是在一个请求处理过程中将原来的url(包括uri和args)改写之后,在继续进行后面的处理,这个重写之后的请求始终都是在同一个location中处理。)
不要因为世态变迁而埋怨,不要因为命运多舛而怨恨.