Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a location block that looks something like:

location / {
    index index.php;
    try_files /legacy$uri /legacy$uri/ $bootstrap?$args;
}

This works create except when I go to http://localhost/ it matches to /legacy/ which isn't what I want. How can I try_files except for when $uri is simply a slash?

share|improve this question
add comment

1 Answer 1

Add another location block:

location  = / {
  //do something
}

As per the documentation, nginx will:

  1. Only match one location block
  2. Will choose the location block based on the following:
    1. Matches using "="
    2. Conventional strings using "^~"
    3. Regular expressions (in the order listed)
    4. All other conventional strings

Therefore, requests for the top level (/) will match the location block above, while all other requests will match your existing location block.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.