Mac配置Apache虚拟主机

前端

Winter

2018-02-27

当你想用自己特定的域名去访问本机的localhost,比如说是用yld.com代替localhost:80时,这个时候Apache配置虚拟主机,就可以完成这个目的。

首先打开虚拟hosts的引用,

打开文件,/etc/apache2/httpd.conf,找到代码

#Include /private/etc/apache2/extra/httpd-vhosts.conf

取消注释,将其这行前的注释符号#去掉。

编辑/etc/apache/extra/httpd-vhosts.conf文件

在该文件中添加如下内容



<VirtualHost *:80>

    ServerAdmin webmaster@yld.com

    DocumentRoot "/Users/website/Dev/yld.com"

    ServerName yld.com

    ErrorLog "/Users/website/Dev/yld.com/error_log"

    CustomLog "/Users/website/Dev/yld.com/access_log" common

    <Directory "/Users/website/Dev/yld.com">

                Options Indexes FollowSymLinks MultiViews

                AllowOverride None

                Require all granted

    </Directory>

</VirtualHost>


重启Apache

sudo apachectl restart

修改Hosts

我们是本地测试开发网站,所以还需要修改hosts文件,来将你的域名yld.com对应本地的IP。

打开文件/etc/hosts,在文件末尾加上

127.0.0.1   yld.com

完成后便可使用域名yld.com访问本地网站了。

第47篇《Mac配置Apache虚拟主机》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0条评论