我正在尝试在我的新 mac OSX 10.9 上设置本地环境。我知道它已经安装了apache,所以我一直在使用它。无论我如何设置 httpd-vhosts.conf/hosts/httpd.conf 文件,在浏览器上访问 localhost 或“test.com”时,我都会不断收到 403 禁止错误。下面列出了错误/文件/其他信息。
这是我访问任一网页时遇到的错误
Forbidden
You don't have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
我的/private/etc/hosts 文件
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 test.com
127.0.0.1 www.test.com
我的/private/etc/apache2/httpd.conf文件
This file is in its original form besides the following changes:
Uncommented Include /private/etc/apache2/extra/httpd-vhosts.conf
我的/private/etc/apache2/extra/httpd-vhosts文件
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot "/Users/[my_name]/Sites/test"
<Directory "/Users/[my_name]/Sites/test">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
其他注意事项
/private/etc/apache/users/
/Users/[my_name]/Sites/test/
文件夹中设置了一个index.html文件使用命令时
sudo apachectl -t
Warning: DocumentRoot [/usr/\xe2\x80\x9c/Users/joshwoelfel/Sites/test\xe2\x80\x9d] does not exist
httpd: Could not reliably determine the server's fully qualified domain name, using Joshs-MacBook-Air.local for ServerName
Syntax OK
我现在不知道该尝试什么。我花了几个小时查看教程和人们发布的其他问题。看来我的文件和权限是正确的!
我刚刚解决了这个问题。尝试添加“要求所有已授予”而不是“允许所有”。
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot "/Users/[my_name]/Sites/test"
<Directory "/Users/[my_name]/Sites/test">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
当您在 mac os 上设置 DocuemntRoot "/Users/xxx/xxx" 时,您必须确保您的 httpd User && Group 有权限读取该目录。默认情况下,/Users/xxx/xxx 所有者是 root,组是 admin,所以你没有权限。如果你的目录组是wheel,它也许可以工作。
验证 DocumentRoot 路径中的每个目录(而不仅仅是 DocumentRoot 本身)对于 Apache 都是可搜索的(+x 权限)。升级我的 Mac 操作系统将我的主目录重置为 700 权限。将其更改为 755 解决了我的问题。
上次升级到 MacOS HighSierra 10.13.4 后,我收到了同样的消息。我尝试过发布的不同解决方案,但真正给我启发的是一篇文章,其中提到当您收到此消息时,通常只是权限问题。所以最后我只需要确保文档根目录的组和所有者(我不保留在我的配置文件路径下)和子目录由 httpd 中指定的相同用户和组拥有。 conf,设置为我的组和用户名。 httpd.conf 中的默认值分别为:_www 和wheel。如果您不确定您的用户名用途
whoami
在终端窗口上。
如果您有兴趣将文件保存在您的个人资料目录下本指南可能会帮助您。