I'm wondering how do I know if a particular location[s] used to process request in nginx
.
E.g.:
# 1
location / {}
# 2
location ~ /[\w\-]+\.html {}
# 3
location ~ /\w+\.html {}
How do I know if URI like /mysite
is processed by 3rd location and not 2nd?
I tend to use add_header
for this matter:
location / {
add_header location 1;
}
location ~ /(\w+\-)\.html {
add_header location 2;
}
location @named {
add_header location named;
}
And I'd like to know is there a better solution or what do you personally use for debugging purposes?
A word of warning on this approach. I found it's a bad idea to use
location
as your debug header, sinceLocation
is a real header used by the HTTP response 301.So if (like me) in your testing you end up with this:
Then your browser will freak out and report
Duplicate headers received from server
. So uselocationdebug
or something safe.The add_header trick is how I would do it to.
I'm at work right now, so I can't test but you might possibly get something in the logfile i you set the
error_log
level to:debug
: you're nginx needs to be built using--with-debug
for this to work, you can check that with thenginx -V
commandnotice
: if debug logging isn't enabledIf you just want to see which block was used, and don't care about returning otherwise valid results, it might be more straight-forward to use
return
rather thanadd_header
.