Why this nginx vhosts configuration keeps redirect other domains to one

I’m trying to add a second domain to nginx. It’s ok to access static files like css in domain2.com but visits to php scripts (e.g domain2.com/index.php) will be 302 redirect to domain1.com (e.g domain1.com/index.php) so I thought the break point must be in the


location ~ \.php$

section, but I can’t make sure where it is. I have been stuck here for a long time, where am i doing wrong? I also tried to copy configuration in the definition guide in http://www.yiiframework.com/doc/guide/1.1/en/quickstart.apache-nginx-config#nginx into the two vhosts conf files, same result.

[OS:windows 2008; Nginx:1.0.12]

nginx.conf


worker_processes  1;


events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    client_max_body_size 50m;


    gzip  on;


    server {

        listen         80;

        server_name     _;

        server_name_in_redirect  off;

        location / {

            root  F:/Web/nginx/html/;

            index index.html;

        }

    }

    include F:/Web/nginx/vhosts/*.conf;

}

F:/Web/nginx/vhosts/domain1.com.conf




    server {

    listen       80;

    server_name  domain1.com;

    charset utf-8;


    location / {

            root   F:/domain1;

        index  index.php;

        try_files $uri $uri/ /index.php?$args;

    }

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   html;

    }

    location ~ \.php$ {

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_split_path_info ^(.+\.php)(.*)$;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  F:/domain1/$fastcgi_script_name;

        include        fastcgi_params;

    }

    location ~ /\.ht {

        deny  all;

    }

}

F:/Web/nginx/vhosts/domain2.com.conf




server {

listen       80;

server_name  domain2.com;

charset utf-8;


location / {

    root   F:/domain2;

    index  index.php;

    try_files $uri $uri/ /index.php?$args;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

    root   html;

}


location ~ \.php$ {

    fastcgi_pass   127.0.0.1:9000;

    fastcgi_split_path_info ^(.+\.php)(.*)$;

    fastcgi_index  index.php;

    fastcgi_param  SCRIPT_FILENAME  F:/domain2/$fastcgi_script_name;

    include        fastcgi_params;

}


location ~ /\.ht {

    deny  all;

}

}

I found the reason.It’s not the nginx configuration problem, it’s php-cgi config. I set doc_root=‘F:/domain1’ so it keeps redirecting.

Hope can help anyone who encounter this question again.