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.

The setup I'm going for is as follows: I want nginx to look for a file in the /test subdirectory, and if it's not there, serve it from it's normal uri. I figured this would be fairly straightforward with try_files. Here's the setup I came up with:

server {
    listen       80;
    server_name  test-server;

    location / {
        root   /opt/www;
        index  index.php;
        try_files /test$uri $uri;
    }
}

This half-works. If I go to http://test-server/something, and there is a /test/something file, it will serve the /test/something file. However, if there isn't a /test/something file, but there is a /something file, it will return a 500 Internal Server error. My best guess is that there's some kind of recursive looping going on, but I don't know what the alternative would be.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The last argument to try_files has to be a guaranteed file. $uri is not acceptable for this. Instead use try_files /test$uri $uri =404;

share|improve this answer
    
That works, thanks! –  Mediocre Gopher Aug 15 '11 at 19:28

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.