I have spent muy tiempo on this and I can't get a solution. I need a way to point the same url but with different root directory to the same application. I don't want to use rewrites because the root directoy name has to be processed by the application and rewrite discards it.
http://www.host.com/a/ --> /var/www/html/project/
http://www.host.com/b/ --> /var/www/html/project/
http://www.host.com/c/ --> /var/www/html/project/
I've managed to configure in nginx an alias directory with a fixed name vdirectory
and make nginx forward the request to fastcgi.
location /vdirectory {
alias /var/www/html/project/;
try_files $uri $uri/ /vdirectory/index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
The above works OK.
Since I don't want to use fixed root directory names but arbitrary ones, this is what I've managed so far:
location ~ ^/(.?)$ {
alias /var/www/html/project/;
try_files $uri $uri/ /$1/index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
Needless to say, it returns 404. It is a good sign because it means regex has recognized the path, but the request isn't forwarded correctly.
The only difference between the working config and the wrong one is /vdirectory
vs ~ ^/(.?)$