Directory fallback

Tobia Conforto tobia.conforto at
Tue Dec 29 20:56:00 MSK 2009


I'm trying to come up with a nginx configuration file for a fallback-like directory structure.

I have the following directories:
/var/www/base/ (generic files)
/var/www/site1/ (files specific to site1)

Given a request for /logo.png, I would like nginx to do the following:
1. serve /var/www/site1/logo.png if exists; otherwise
2. serve /var/www/base/logo.png.

The matter is complicated by the presence of PHP files. Given a request for /index.php (possibly in the same directory as image files...) nginx should:
1. serve /var/www/site1/index.php through FastCGI, if the php file exists; otherwise
2. serve /var/www/base/index.php through FastCGI.

Can anybody please suggest the optimal combination of document_root, alias, location, rewrite, try_files or such options to use? I would like to avoid client-side redirects. Everything else is ok.


More information about the nginx mailing list