开启虚拟主机配置功能
sudo vi /etc/apache2/httpd.conf
在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“#”,保存并退出。
sudo apachectl restart //重启Apache
配置虚拟主机
sudo vi /etc/apache2/extra/httpd-vhosts.conf //配置虚拟主机文件httpd-vhost.conf
##配置的格式参考
<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host2.example.com //主机邮箱地址
DocumentRoot "/usr/docs/dummy-host2.example.com" //站点根目录
ServerName dummy-host2.example.com //站点虚拟域名
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log" //错误日志输出
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
<Directory "/usr/docs/dummy-host2.example.com"> //站点根目录 文件权限相关
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>