我想使用nginx在同一服务器上托管2个不同的域。我通过@属性将两个域都重定向到了该主机。尽管我配置了2个不同的服务器块,但是每当我尝试访问第二个域时,它都会重定向到第一个域。
这是我的配置。
server {
listen www.domain1.com:80;
access_log /var/log/nginx/host.domain1.access.log main;
root /var/www/domain1;
server_name www.domain1.com;
location ~ \.php$ {
# Security: must set cgi.fixpathinfo to 0 in php.ini!
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include /etc/nginx/fastcgi_params;
}
}
server {
listen www.domain2.com:80;
access_log /var/log/nginx/host.domain2.access.log main;
root /var/www/domain2;
server_name www.domain2.com;
location ~ \.php$ {
# Security: must set cgi.fixpathinfo to 0 in php.ini!
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include /etc/nginx/fastcgi_params;
}
}
我怎样才能解决这个问题?谢谢。
server {}
块中,sever_name指令都是通配符:.domain1.com
和.domain2.com
。使用这些地址时,将它们更改为server_name www.domain1.com domain1.com;
,server_name www.domain2.com domain2.com;
现在将为每个站点显示正确的页面。