首先,修改/opt/lampp/etc/httpd.conf文件,开启虚拟主机功能
找到配置项
# Virtual hosts
# Include etc/extra/httpd-vhosts.conf
修改为
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
然后,修改:/opt/lampp/etc/extra/httpd-vhosts.conf文件
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/home/www/aaa" ServerName www.aaa.com ServerAlias www.dummy-host.example.com ErrorLog "logs/dummy-host.example.com-error_log" CustomLog "logs/dummy-host.example.com-access_log" common </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/home/www/bbb" ServerName www.bbb.com ErrorLog "logs/dummy-host2.example.com-error_log" CustomLog "logs/dummy-host2.example.com-access_log" common </VirtualHost>
然后,重启apache,按照上面配置后,www.aaa.com对应/home/www/aaa目录;www.bbb.com对应/home/www/bbb目录。