Cannot change default root path

I am new user of nginx, I installed it as replace of apache on cpanel
server for one very busy site.
I installed it to default folder /usr/local/nginx and setup it working
with php fastcgi spawn, but it only works from nginx default root i.e.
only from /usr/local/nginx/html

I need its root to be changed for different vhosts paths like
/home/user/public_html but look like all my commands like root
/home/user/public_html; are some why ignored by nginx and it is always
trying to run files from /usr/local/nginx/html

I checked in error log - and there are no errors displayed - only in
access log I see message that file not found 404 error.

Can anyone help me with this basic setup?

You can do one of two things, both quite straight forward. First, you
can
build it with the --prefix set to something other than /usr/local/nginx
or
you can supply a full-path with your configurations “root” directive.

You should have in your config somewhere a line like this:

root html;

Changing it like this should help:

root /var/www;

Of course you should replace /var/www with the proper root. Also, for
sub-locations that need a separate root, you may find the “alias”
directive
useful, like so:

server {
listen 80;
root /var/www;
location /funstuff {
alias /home/me/funstuff;
}
}

  • Merlin

Actuall now I found this problem is only happens with my php files.
For other non php files all paths are working ok.
For example this config is working properly:
location / {
index index.html index.php;
root /home/user/public_html;
}

but this one not working:

location ~ .php$ {
fastcgi_pass 127.0.0.1:10000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/home/user/public_html$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}

On this config all non-php files are served correctly from correct
locations, but php files are getting error 404 file no found.
But when I setup nginx default path as /usr/local/nginx/html - then even
php working properly.

So what can be problem with this fastcgi config?

I even added there root inside of php location and outside of it - and
it still did not helped. All root directives like ignored by fastcgi…

What does the error log show when you try to serve the pages from your
home
directory?

Merlin wrote:

What does the error log show when you try to serve the pages from your
home
directory?

Access log show only 404 error like this one:
“GET /index.php HTTP/1.1” 404

No other errors logged anywhere else.

On Wed, Feb 25, 2009 at 11:38:22PM +0100, Y. Yaax wrote:

location ~ .php$ {
php working properly.

So what can be problem with this fastcgi config?

Where you .php files are located ?
This configuraiton try to execute them as

/home/user/public_html/…

On Wed, Feb 25, 2009 at 02:12:30PM -0800, Merlin wrote:

root /var/www;

Of course you should replace /var/www with the proper root. Also, for
sub-locations that need a separate root, you may find the “alias” directive
useful, like so:

server {
listen 80;
root /var/www;
location /funstuff {
alias /home/me/funstuff;

For this case it’s better to use just “root”:

location /funstuff {
root /home/me;

The “alias” is required if you need to replace location part.

Igor S. wrote:

On Wed, Feb 25, 2009 at 11:38:22PM +0100, Y. Yaax wrote:

location ~ .php$ {
php working properly.

So what can be problem with this fastcgi config?

Where you .php files are located ?
This configuraiton try to execute them as

/home/user/public_html/…

php files are located in this folder /home/user/public_html/ - in fact
they are served correctly by apache from same folder on another port.
But fastcgi cannot find them, there…

On Thu, Feb 26, 2009 at 11:11:52AM +0100, Y. Yaax wrote:

/home/user/public_html/…

php files are located in this folder /home/user/public_html/ - in fact
they are served correctly by apache from same folder on another port.
But fastcgi cannot find them, there…

Could you show the full server configuration ?

Igor S. wrote:

On Thu, Feb 26, 2009 at 11:11:52AM +0100, Y. Yaax wrote:

/home/user/public_html/…

php files are located in this folder /home/user/public_html/ - in fact
they are served correctly by apache from same folder on another port.
But fastcgi cannot find them, there…

Could you show the full server configuration ?

server {
listen ip:80;
server_name domain.com;

    error_log  logs/vhost-error_log warn;

    root  /home/user/public_html;
    location / {
        index index1.html;
        root  /home/smf4u/public_html;
    }

    location ~ \.php$ {
            root  /home/user/public_html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME 

$document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME
/home/user/public_html$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
}

I tried both ways fastcgi_param SCRIPT_FILENAME
/home/user/public_html$fastcgi_script_name; and fastcgi_param
SCRIPT_FILENAME $document_root$fastcgi_script_name;

  • both ways have same error file not found.

Ok, finally I succeed to run php correctly, for this I was required to
replace spawn fcgi with php-fpm. It look like nginx works better for
php-fpm then for spawn-fcgi, at least config was easier.

Y. Yaax wrote:
Sorry I did error there while editing it should be
server {
listen ip:80;
server_name domain.com;

     error_log  logs/vhost-error_log warn;

     root  /home/user/public_html;
     location / {
         index index1.html;
         root  /home/user/public_html;
     }

     location ~ \.php$ {
             root  /home/user/public_html;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param SCRIPT_FILENAME

$document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_FILENAME
/home/user/public_html$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
}

I tried both ways fastcgi_param SCRIPT_FILENAME
/home/user/public_html$fastcgi_script_name; and fastcgi_param
SCRIPT_FILENAME $document_root$fastcgi_script_name;

  • both ways have same error file not found.