- 开启Apache的mod_rewrite、mod_vhost_alias功能模块
- 引入http-vhosts.conf文件
- 添加VirtualHost配置
- 修改hosts文件
//打开文件httpd.conf,
sudo vim /etc/apache2/httpd.conf
//找到mod_rewrite.so,删除#,开启路由rewrite功能、虚拟机模块
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
引入http-vhosts.conf文件
//打开文件httpd.conf
sudo vim /etc/apache2/httpd.conf
//找到# Virtual hosts的引入文件,删除#
Include /private/etc/apache2/extra/httpd-vhosts.conf
添加VirtualHost配置
//打开http-vhosts.conf文件,添加虚拟主机配置
sudo vim /private/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName coding.com
ServerAdmin coding.com
DocumentRoot "/Users/anneason/www/"
ErrorLog "/private/var/log/apache2/coding.com-error_log"
CustomLog "/private/var/log/apache2/coding.com-access_log" common
</VirtualHost>
修改hosts文件
//打开hosts文件
sudo vim /etc/hosts
127.0.0.1 coding.com
在浏览器打开"conding.com",返回本地项目,配置成功,End