centos7下如何配置多个域名在一台服务器上?或者这么说:centos7上如何绑定多个站点到apache上?
我的apache是使用yum install httpd方式安装的。
1.仿照windows IIS的主机头方式给apache绑定多个域名,让apache站点共用80端口,在apache的扩展配置目录添加xhost.conf文件(文件名随意,但后缀必须是conf)
比如,绑定两套域名a.com,b.com到apache。
cat > /etc/httpd/conf.d/xhost.conf << EOF
<VirtualHost *:80>
ServerName a.com
ServerAlias a.com www.a.com
DocumentRoot /var/www/html/a.com
DirectoryIndex index.htm index.html index.php
</VirtualHost>
<Directory "/var/www/html/a.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName b.com
ServerAlias b.com www.b.com
DocumentRoot /var/www/html/b.com
DirectoryIndex index.htm index.html index.php
</VirtualHost>
<Directory "/var/www/html/b.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
EOF
2.给指定的web目录里放上网页文件(略过)
3.重启apache服务
systemctl restart httpd
4.修改host域名解析,便于我们访问测试站点
如果你的是windows,那就修改C:\Windows\System32\drivers\etc\hosts,添加上对应的域名和ip,如:
192.168.73.250 a.com www.a.com b.com www.b.com c.com www.c.com
5.如果这样不行,那估计是你的站点配置文件没有被apache加载到。
解决办法:在/etc/httpd/conf/httpd.conf的最后加入一行参数IncludeOptional conf.d/*.conf
或直接用下面一条命令
echo "IncludeOptional conf.d/*.conf" >> /etc/httpd/conf/httpd.conf
记得重启apache服务(systemctl restart httpd)
老铁,双击666