需求: 同一IP, 80端口,多个子域名访问

a.xxx.com 指向目录 var/www/html/a.xxx.com
b.xxx.com 指向目录 var/www/html/b.xxx.com

我的做法是 修改 etc/nginx/sites-avaliable/default 如下

server {
listen 80 ;
listen [::]:80 ;
server_name a.xxx.com ;

root /var/www/html/a.xxx.com;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

location / {
index index.html index.htm index.php default.html default.htm default.php;
}
location ~ .\.php(\/.)*$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;

#fastcgi_pass 127.0.0.1:9000;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

}

}

server {
listen 80 ;
listen [::]:80 ;
server_name b.xxx.com ;

root /var/www/html/b.xxx.com;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

location / {
index index.html index.htm index.php default.html default.htm default.php;
}
location ~ .\.php(\/.)*$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;

#fastcgi_pass 127.0.0.1:9000;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

}

}

问题是 nginx 无法成功重启,有错误,将第二个 80端口 改成其他可以正常启动,但是域名访问失效,只能通过端口来区分访问目录,在网上搜了一大把,没有一个靠谱的,这应该是最基础的了吧,往大神指点一二。不甚感激,搞得头大!