mac 上配置apache虚拟主机

转自:https://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/

编辑你的 apache 配置文件:

vim /etc/apache2/httpd.conf

去掉这一行的注释:

Include /peivate/etc/apache2/extra/httpd-vhosts.conf

这时,apache 将会加载 httpd-vhosts.conf 这个配置文件

编辑httpd-vhost.conf 配置文件:

vim /etc/apache2/extra/http-vhosts.conf

这里给一个例子:

<VirtualHost *:80>
        DocumentRoot "/Users/Jason/Documents/workspace/dev"
        ServerName jason.local
        ErrorLog "/private/var/log/apache2/jason.local-error_log"
        CustomLog "/private/var/log/apache2/jason.local-access_log" common

        <Directory "/Users/Jason/Documents/workspace/dev">
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
上面的配置表明,我可以通过访问http://jason.local 访问到本地的/User/Json/Documemts/workspace/dev 下的文件,

重启apache:apachectl restart
最后一步,编辑hosts文件:
vim /etc/hosts
添加:127.0.0.1 json.local
运行以下命令清除DNS缓存:dscacheutil -flushcache
如果你想验证配置文件是否有错误,运行:apachectl configtest



posted @ 2016-10-30 12:31  小白洗澡澡  阅读(3817)  评论(0)    收藏  举报