last-完成rewrite指令的处理,之后搜索对应的URI和location; break-完成rewrite指令的外理
[[email protected] app]# cat /app/server/nginx/conf/vhosts/default.conf server { listen 80 default_server; server_name localhost; root /app/www; location / { root /app/www/html; index index.html index.htm; rewrite "/x/t.html" /y/t.html break; } location /y/ { root /app/www/html/other; } }
[[email protected] other]# tree /app/www/html//app/www/html/├── index.html├── other│ └── y│ └── t.html└── y └── t.html 3 directories, 3 files[[email protected] other]# cat /app/www/html/y/t.html yyy[[email protected] other]# cat /app/www/html/other/y/t.html other----->last[[email protected] other]#
[[email protected] app]# curl http://192.168.1.24/x/t.html yyy
当请求/x/t.html,符合rewrite规则,所以进行调整,调整的地址为/y/t.html,由于使用的flag是break,所以在 “location /”中进行跳转,结果是/app/www/html/y/t.html。但如果flag为last,那么/y/t.html将在"server"标签中重新执 行,由于存在一个“location /y/”,所以跳转被重新指定到“location /y/”标签,所以这个时候的结果为/app/www/html/other/y/t.html
如下测式:
[[email protected] other]# cat /app/www/html/other/y/t.html other----->last [[email protected] other]# cat /app/server/nginx/conf/vhosts/default.conf server { listen 80 default_server; server_name localhost; root /app/www; location / { root /app/www/html; index index.html index.htm; #rewrite "/x/t.html" /y/t.html break; rewrite "/x/t.html" /y/t.html last;#注意这里已经改成last } location /y/ { root /app/www/html/other; } } [[email protected] other]# curl http://192.168.1.24/x/t.html other----->last
注意:使用last,如果配置不当,可能引起死循环。
时间: 2024-11-06 12:18:56