Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 want all urls under /media/thumbnails to be served from disk, and if the file doesn't exist, from another server, but without redirecting the client. I believed this should work but I can't find what is wrong with it:

    location /media/thumbnails {
            try_files $uri @thumbnail_generator;

    location /media {
            root /home/plinio/nginx_test;

    location @thumbnail_generator {

Even after creating the /home/plinio/nginx_test/media/thumbnails/test.txt file, a request to /media/thumbnails/test.txt is still being internally redirected to @thumbnail_generator.

share|improve this question

You haven't shown us your complete vhost configuration, so I can't say for sure, but your use of the root directive in the /media location block suggests that you might not have a root directive in the top-level vhost config.

Nginx location blocks are not cumulative; it finds the best single match location block (according to the rules specified in the documentation), and uses that. Hence, if you don't have one in the vhost config itself, your lookups for /media/thumbnails/text.txt aren't going to where you think they are on the filesystem, and hence the file doesn't exist and the internal redirect kicks in.

By the way, you can trivially find these sorts of problems by turning on debug logging and looking at the vhost error log. Nginx is quite good about logging what it's doing to process a request, and the completely wrong file path is usually a pretty big clue what you've done wrong.

share|improve this answer
I've changed my strategy and this is isn't a problem anymore, thanks for your help. I didn't fully solve this problem but it seems the issue was that I thought the "try_files $uri ..." directive would try to the use '/media' location first, and only on failure would use the @thumbnail_generator url. I believe a root directive before try_files would've solved it. – Plinio May 3 '12 at 20:40

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.