You must add “^ ~” to give this match a higher priority than the regular expression location blocks.
location ^~ /test/ { return 404; }
Otherwise, you will encounter some difficult situation. For example, if you have another location block, for example
location ~ \.php$ { ... }
and someone sends a request http://your_domain.com/test/bad.php , this block of the location of the regular expression will be selected by nginx to serve the request. Obviously, this is not what you want. So be sure to put "^ ~" in this location block!
Link: http://wiki.nginx.org/HttpCoreModule#location
Chuan Ma Mar 18 '13 at 16:13 2013-03-18 16:13
source share