Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

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呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...