MacBook搭建虚拟主机

前边文章讲了mac上搭建好了本地服务器,现在来搭建虚拟主机,使得本地也能以一个域名的形式访问服务器
1.参考上一篇搭建本地服务器,备份配置文件:http://blog.csdn.net/qq_25639809/article/details/77988470
2.编辑httpd.conf文件,输入命令:

sudo vim /etc/apache2/httpd.conf

将Include /private/etc/apache2/extra/httpd-vhosts.conf这行前的注释符号#去掉。
3.编辑httpd-vhosts.conf文件,输入命令:

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

按i进入编辑模式,在httpd-vhosts.conf 中默认的两个VirtualHost删除或者加#注释
然后添加以下内容,beta.test.com可任意起名,注意对应自己的服务器路径(我将localhost对应sites文件夹,beta.test.com对应sites/test文件夹)

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "/Users/lax/sites"
    ServerName localhost
    ErrorLog "/private/var/log/apache2/beta.test.com-error_log"
    CustomLog "/private/var/log/apache2/beta.test.com-access_log" common
    <Directory "/Users/lax/sites">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@wzrm.vxinghe.com
    DocumentRoot "/Users/lax/sites/test"
    ServerName beta.test.com
    ErrorLog "/private/var/log/apache2/beta.test.com-error_log"
    CustomLog "/private/var/log/apache2/beta.test.com-access_log" common
    <Directory "/Users/lax/sites/test">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Require all granted
    </Directory>
</VirtualHost>

按esc,输入:wq回车保存退出

4.修改hosts文件,来将你的域名beta.test. com对应本地的IP,输入命令:

sudo vim /etc/hosts

添加一行内容:

127.0.0.1       beta.test.com

5.重启服务器

sudo apachectl restart

6.在浏览器中访问localhost和beta.test.com查看

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值