@y3093
2015-07-31T12:06:42.000000Z
字数 1909
阅读 3618
打开“终端”软件,输入如下命令进行修改Host文件:
sudo vim /etc/hosts
在Host文件中添加:
127.0.0.1 website.com
127.0.0.1 www.website.com
如图:
访问Host文件需要权限,将提示输入密码,输入你本机的密码即可。输入时页面不会显示位数,光标位置也不会移动。输入完毕后按回车即可。
添加完成后,按ESC退出编辑状态,按Shift + ZZ (注意是按两次Z)保存并退出。

使用命令行或Finder打开httpd.conf文件:
sudo vim /Applications/XAMPP/xamppfiles/etc/httpd.conf
在httpd.conf文件中,搜索“httpd-vhosts.conf”,找到如下内容,取消第二行的注释(删除前方的#号):
# Virtual hosts# Include etc/extra/httpd-vhosts.conf
< Directory "/Users/yangjuanfang/Jane/project/chineseculture”># Options Indexes FollowSymLinks ExecCGI Includes # don't permission see listOptions AllAllowOverride AllOrder allow,denyAllow from all< / Directory>
# Deny access to the entirety of your server's filesystem. You must# explicitly permit access to web content directories in other# < Directory> blocks below.< Directory />`AllowOverride noneRequire all denied`< / Directory>
将高亮的两行内容注释,并添如下内容:
Options AllAllowOverride AllOrder allow,denyAllow from all
如图:

第二个方法将开放所有文件的访问权限,涉及安全性问题…… 待修改
使用命令行或Finder打开httpd-vhost.conf文件,配置虚拟主机,
sudo vim /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
添加如下内容:
< VirtualHost *:80>ServerAdmin webmaster@website.comDocumentRoot "/Users/yangjuanfang/Jane/project/website”ServerName website.comServerAlias www.website.comErrorLog "logs/dummy-host.website.com-error_log"CustomLog "logs/dummy-host.website.com-access_log" common</VirtualHost>
注意事项:
1. 缺乏访问文件、目录权限时,浏览页面将提示403错误;请按第二部操作配置权限。
2. 遇到无法浏览情况,可查看错误日志以排查问题。(错误日志:/Applications/XAMPP/xamppfiles/logs/error_log)
配置时,遇到访问一直提示404问题,文件路径没错。纠结半天查看错误日志,发现如下内容:
Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf:24AH00112: Warning: DocumentRoot [/Users/yangjuanfang/Jane/project/chineseculture**\xe2\x80\x9d**] does not exist
细心的朋友应该能发现,在路径末尾多出了“\xe2\x80\x9d”字符,这是因为路径双引号为全角符号导致的……
将双引符号改为半角即可。不知道为何,用Mac修改Apache的配置文件时,再怎么输入半角双引号都会自动转为全角;也是醉了……
最终以复制粘贴半角双引号解决。
参考文章/文档: