Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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

Your Answer


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.