Linux Apache 虚拟主机配置指南
假设 VPS 的 IP 地址为 58.130.17.168,且有两个域名 domain1.com 与 domain2.com 均指向该 IP。
编辑 /etc/httpd/conf/httpd.conf 配置文件,在文件末尾追加以下内容:
ServerName 58.130.17.168
NameVirtualHost 58.130.17.168
ServerName domain1.com
DocumentRoot /var/www/domain1.com
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
ServerName domain2.com
DocumentRoot /var/www/domain2.com
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
随后在 /var/www/domain1.com 和 /var/www/domain2.com 目录下分别创建各自的 index.html 文件。
echo "domain1">/var/www/domain1.com/index.html
echo "domain2">/var/www/domain2.com/index.html
在浏览器中访问 http://domain1.com 和 http://domain2.com 即可验证配置效果。