I have a few exposed JSON
scripts / programs for quick information gathering from a server. I use nginx to expose those as just raw urls. So given the following locations:
location ~ ^/api/status/? {
rewrite ^(.*)$ /path/to/some/handler/wan.handler;
}
location ~ ^/api/status-lan/? {
rewrite ^(.*)$ /path/to/some/handler/lan.handler;
}
Why does nginx
match my status-lan
call to the status
location? So I can view my output from /api/status/
just fine, but if I view /api/status-lan/
I get the status
location instead.
Because the location is a regular expression, and this regular expression:
means "starts with /api/status, followed by an optional trailing slash", what comes after the match doesn't matter.
The config should probably be:
I.e. match the whole url, not just the start of it. If in doubt, turn on the rewrite log as it'll make it obvious what is happening, and why.