Great answer slarek. We did something very similar. Instead of editing index.php we setup separate folders outside of magento's codebase, and include mage.php from those folders, and then edit the etc_dir (and other dirs) like in your method above.
folder structure:
/www/client1
/www/client2
/www/client3
/www/clientX
/www/magento
Inside each of the client folders are:
- /www/clientx/etc/local.xml (with unique database defined, and unique redis db)
- /www/clientx/etc/modules (this is a sym link to /www/magento/app/etc/modules)
- /www/clientx/index.php
in /www/clientx/index.php
define('MAGENTO_ROOT', '/www/magento');
...(rest of index.php is business as usual)...
$client = isset($_SERVER['CLIENT_ID']) ? $_SERVER['CLIENT_ID'] : '';]
Mage::run($mageRunCode, $mageRunType, array('etc_dir'=>'../'.$client));
We set
$_SERVER['CLIENT_ID'] in Nginx with
`fastcgi_param CLIENT_ID clientx; `