Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I just did a clean install of nginx + php-fpm on a VPS running Ubuntu 10.10, nginx is serving and PHP is working fine, but I'm not able to add vhosts to it. Well, I can add them, but only one works, the rest go to this first one.

This is my first vhost, for host1:

server {

    listen   80;
    server_name host1;

    access_log /var/log/nginx/host1.log;
    error_log /var/log/nginx/host1.error.log;

    location / {
        root  /var/www/vhosts/host1/;
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_pass  unix:/var/run/php5-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME  /var/www/vhosts/host1/$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_index  index.php;
    }
}

And the second one, for host2:

server {

    listen   80;
    server_name host2;

    access_log /var/log/nginx/host2.log;
    error_log /var/log/nginx/host2.error.log;

    location / {
        root  /var/www/vhosts/host2/;
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_pass  unix:/var/run/php5-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME  /var/www/vhosts/host2/$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_index  index.php;
    }
}

The problem is, when I go to http://host1 everything is fine, but on http://host2, it just shows host1!

I don't have Apache installed and everything comes from repos. Any pointers?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Don't know what you have wrong, but take a look at my conf file, it worked.

server {
    server_name localhost;
    root /opt/local/html;
    index index.php index.html index.htm;

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /opt/local/html/$fastcgi_script_name;
        include        /opt/local/etc/nginx/fastcgi.conf;
    }        
}


server {
    server_name  pma;
    root /opt/local/www/pma;
    index index.php index.html index.htm;

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /opt/local/www/pma/$fastcgi_script_name;
        include        /opt/local/etc/nginx/fastcgi.conf;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.