Welcome! Log In Create A New Profile

Advanced

Conditional root directory

Posted by donkeyy 
Conditional root directory
August 09, 2013 03:18PM
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
Re: Conditional root directory
August 09, 2013 03:27PM
Looks like your root and document_root are not set properly when using fallback.
Re: Conditional root directory
August 09, 2013 03:38PM
Isn't $document_root equal to $root? Anyway, any idea how to solve it?
Re: Conditional root directory
August 09, 2013 05:39PM
It should be when root is set properly, when you get " No input file specified" it means php can't find the php file so doc root is pointing to a wrong path, there should be a way to display where root is pointing to so you can find out where its going wrong, also check php.ini for path/openbasedir/docroot values. Or pass a fixed path instead of $document_root.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 296
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready