Answer the question
In order to leave comments, you need to log in
Apache + Nginx, how to search for a file in another directory?
I am writing a website (CMS) with subdomains, and therefore there are files that are in the root, and there are files for a specific domain. I want to make sure that if the file was not found, then search in the domain directory. For example, a file can be placed both in the root and along the path "/domains/cms.site.com/", thus, referring to cms.site.com/test.png , a search should be made in the root and if the file is not found there , then try to find it along the path "/domains/cms.site.com/test.png". I am using Apache 2.4 + Nginx 1.9. I'm not strong in setting up Nginx, but this is one of the customer's conditions. A bit of code:
In htaccess, this instruction looks like this (but it only works if nginx static processing is disabled, which I would not like to do):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/domains/.*
RewriteRule ^(.*)$ /domains/%{HTTP_HOST}/$1 [L]
location / {
root "%hostdir%";
try_files $uri $uri/ /domains/$http_host/$uri =403;
}
location /domains {
root %hostdir%/domains/;
}
location ~* ^.+\.(?!php$|cgi$|html$|htm$|phtml$)\w*$ {
root "%hostdir%";
try_files $uri /domains/$http_host/$uri =404;
expires 7d;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question