nginx的多个location都匹配到了请求,那么怎么知道具体走的是哪个location?

nginx的多个location都匹配到了请求,那么怎么知道具体走的是哪个location?

有没有什么日志可以打印出来是哪个location匹配的?

`
location ^~ /test {

rewrite ^/test/(.*) /test/aaa/$1;

}

location ^~ /test/a2 {

rewrite ^/test/(.*) /test/aaa/$1;

}
`

类似以上的,访问 http://xx/test/a2/xxx ,日志中怎么打印是走的哪个location呢?

阅读 6k
1 个回答

你这个location是普通匹配,普通匹配的话,优先级是最长。
location ^~ /test/a2
为了验证这个,你可以在日志中验证。
首先你需要开启两个配置,在server里面定义:
1.设置下error_log的等级
error_log logs/error.log notice;
2.开启重写的日志输出设置
rewrite_log on;

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题