Suppose I have these paths:
/
/something # this path is variable (any characters except /)
/api/v1/something
What is the best nginx config to capture this requirement? The following is not working for m:
server {
listen 8080;
location ~^/(?:.*)$ {
...
}
location / {
...
}
location /api/v1/something {
...
}
}
Your regular expression matches everything which means it always wins! See the documentation to understand how Nginx chooses which
location
block to process a request.You do not need to use a regular expression
location
.First define
location
blocks for the single URIs using the=
operator:Then use the default
location
to catch anything else:The above
location
blocks can appear in any order. Only regular expressions are sensitive to evaluation order.