如何在Macbook上配置Apache虛擬主機(jī)
在hosts中添加域名
# Copyright (c) 2014-2016, racaljk.
# https://github.com/racaljk/hosts
# Last updated: 2016-10-20
# This work is licensed under a CC BY-NC-SA 4.0 International License.
# https://creativecommons.org/licenses/by-nc-sa/4.0/
# Localhost (DO NOT REMOVE)
127.0.0.1 localhost
127.0.0.1 blog.xxx.cn
::1 localhost ip6-localhost ip6-loopback
編輯httpd.conf文件
輸入命令:
vi /etc/apache2/httpd.conf
將Include /private/etc/apache2/extra/httpd-vhosts.conf這行前的注釋符號#去掉。
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
# Local access to the Apache HTTP Server Manual
#Include /private/etc/apache2/extra/httpd-manual.conf
# Distributed authoring and versioning (WebDAV)
#Include /private/etc/apache2/extra/httpd-dav.conf
# Various default settings
#Include /private/etc/apache2/extra/httpd-default.conf
編輯httpd-vhosts.conf文件
輸入命令:
vi /etc/apache/extra/httpd-vhosts.conf
在文件后面追加如下網(wǎng)站配置
<VirtualHost *:80>
#ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/blog.xxx.cn/"
ServerName blog.xxx.com
ErrorLog "/private/var/log/apache2/dummy-host2.example.comblog.xxx.cn-error_log"
#CustomLog "/private/var/log/apache2/blog.xxx.cn-access_log" common
</VirtualHost>
重啟apache服務(wù)器
sudo apachectl restart
測試服務(wù)器配置
在瀏覽器中輸入:
http://blog.xxx.cn
查看網(wǎng)站容诬。