Hello, I would like to implement conditional root directory in nginx. If one directory exists, nginx will use it as root dir, otherwise, different dir will be used. Here is my solution so far:
server {
listen 80;
server_name *.dev;
root /var/www/$host/public;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string @fallback;
}
location @fallback {
root /var/www/$host;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
There is a problem with @fallback (when public dir doesn't exists) - php files weren't processed (in browser I get error: No input file specified.).
Anyone have a solution or better idea to accomplish what I need?
Thanks
server {
listen 80;
server_name *.dev;
root /var/www/$host/public;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string @fallback;
}
location @fallback {
root /var/www/$host;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
There is a problem with @fallback (when public dir doesn't exists) - php files weren't processed (in browser I get error: No input file specified.).
Anyone have a solution or better idea to accomplish what I need?
Thanks