[关闭]
@y3093 2015-07-31T12:06:42.000000Z 字数 1909 阅读 3618

Mac OSX配置XAMP虚拟主机 多站点

一、修改Host文件

打开“终端”软件,输入如下命令进行修改Host文件:

  1. sudo vim /etc/hosts

在Host文件中添加:

127.0.0.1 website.com
127.0.0.1 www.website.com

如图:
修改Host文件
访问Host文件需要权限,将提示输入密码,输入你本机的密码即可。输入时页面不会显示位数,光标位置也不会移动。输入完毕后按回车即可。

添加完成后,按ESC退出编辑状态,按Shift + ZZ (注意是按两次Z)保存并退出。
修改Host文件

二、修改httpd.conf文件

使用命令行或Finder打开httpd.conf文件:

  1. sudo vim /Applications/XAMPP/xamppfiles/etc/httpd.conf

1、开启虚拟主机功能

在httpd.conf文件中,搜索“httpd-vhosts.conf”,找到如下内容,取消第二行的注释(删除前方的#号):

  1. # Virtual hosts
  2. # Include etc/extra/httpd-vhosts.conf

2、配置访问目录权限

  1. < Directory "/Users/yangjuanfang/Jane/project/chineseculture”>
  2. # Options Indexes FollowSymLinks ExecCGI Includes # don't permission see list
  3. Options All
  4. AllowOverride All
  5. Order allow,deny
  6. Allow from all
  7. < / Directory>
  1. # Deny access to the entirety of your server's filesystem. You must
  2. # explicitly permit access to web content directories in other
  3. # < Directory> blocks below.
  4. < Directory />
  5. `AllowOverride none
  6. Require all denied`
  7. < / Directory>

将高亮的两行内容注释,并添如下内容:

  1. Options All
  2. AllowOverride All
  3. Order allow,deny
  4. Allow from all

如图:
修改httpd-vhost.conf文件

第二个方法将开放所有文件的访问权限,涉及安全性问题…… 待修改

三、修改httpd-vhost.conf:

使用命令行或Finder打开httpd-vhost.conf文件,配置虚拟主机,

  1. sudo vim /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf

添加如下内容:

  1. < VirtualHost *:80>
  2. ServerAdmin webmaster@website.com
  3. DocumentRoot "/Users/yangjuanfang/Jane/project/website”
  4. ServerName website.com
  5. ServerAlias www.website.com
  6. ErrorLog "logs/dummy-host.website.com-error_log"
  7. CustomLog "logs/dummy-host.website.com-access_log" common
  8. </VirtualHost>

注意事项:
1. 缺乏访问文件、目录权限时,浏览页面将提示403错误;请按第二部操作配置权限。
2. 遇到无法浏览情况,可查看错误日志以排查问题。(错误日志:/Applications/XAMPP/xamppfiles/logs/error_log)


配置时,遇到访问一直提示404问题,文件路径没错。纠结半天查看错误日志,发现如下内容:

  1. Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf:24
  2. AH00112: Warning: DocumentRoot [/Users/yangjuanfang/Jane/project/chineseculture**\xe2\x80\x9d**] does not exist

细心的朋友应该能发现,在路径末尾多出了“\xe2\x80\x9d”字符,这是因为路径双引号为全角符号导致的……

将双引符号改为半角即可。不知道为何,用Mac修改Apache的配置文件时,再怎么输入半角双引号都会自动转为全角;也是醉了……
最终以复制粘贴半角双引号解决。

参考文章/文档:

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注