I have this config that works as expected in an empty server { } definition
location ^~ /foo/ {
al
You are probably looking for break.
location ^~ /foo/ {
alias /var/www/foo/;
break;
}
From the HttpRewriteModule documentation:
last- completes processing of current rewrite directives and restarts the process (including rewriting) with a search for a match on the URI from all available locations.
break- completes processing of current rewrite directives and non-rewrite processing continues within the current location block only.Note that outside location blocks, last and break are effectively the same.