Nick
Nick

Reputation: 10539

nginx ignores root with combination of try_files

Suppose a website is in /www/site/ I have a directory /www/site/images/ where images are.

i want to use try_files in a way file to be searched first in /www/site.optimized/images/ then in /www/site/images/ . This is non working, seems "root" is ignored here.

location ~* ^\/images\/.+\.(jpg|jpeg)$ {
        root                    /www/;
        try_files               /site/$uri /site.optimized/$uri;
}

Upvotes: 1

Views: 605

Answers (1)

Nick
Nick

Reputation: 10539

after more research I found this solution:

    location ~* ^\/images\/.+\.(jpg|jpeg)$ {
            root                    /www/site.optimized/;
            try_files               $uri @cache_fallback;
    }

    location @cache_fallback {
            root                    /www/site/;
    }

it first looks in optimized, then it uses different "named" location in order to check in normal directory.

Upvotes: 2

Related Questions