我刚刚在运行 Ubuntu 10.10 的 VPS 上全新安装了 nginx + php-fpm,nginx 正在运行,PHP 运行良好,但我无法向其中添加虚拟主机。好吧,我可以添加它们,但只有一个有效,其余的都归第一个。
这是我的第一个 vhost,用于 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;
}
}
第二个针对 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;
}
}
问题是,当我去http://主机1一切都很好,但是http://host2,它只显示host1!
我没有安装 Apache,所有内容都来自 repos。有什么指示吗?
答案1
不知道你错在哪儿,但看一下我的配置文件,它起作用了。
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;
}
}