我在 Mac OS X 10.5 上运行 Macports apache2。每当我在默认文件夹中配置虚拟主机时,它都可以正常工作,但是当我在主目录中配置虚拟主机时,我收到“403 Forbidden”错误。
如何在我的主目录中配置虚拟主机?
以下是我访问“devel.mysite.com”时出现“403 Forbidden”的配置:/opt/local/apache2/conf/extra/httpd-vhosts.conf:DocumentRoot“/opt/local/apache2/htdocs”ServerName * #CustomLog“”common
<VirtualHost *:80>
#DocumentRoot "/opt/local/apache2/htdocs/mysite"
DocumentRoot "/Users/myuser/Sites/mysite"
ServerName devel.mysite.com
</VirtualHost>
错误信息在/opt/local/apache2/logs/devel.mysite.com-error_log
:
[Sat Apr 17 19:54:49 2010] [error] [client 127.0.0.1] client denied by server configuration: /Users/myuser/Sites/mysite/
当我取消注释该行以创建 DocumentRoot 时/opt/local/apache2/htdocs/mysite
,它可以工作: DocumentRoot“ / opt / local / apache2 / htdocs” ServerName * #CustomLog“” common
<VirtualHost *:80>
DocumentRoot "/opt/local/apache2/htdocs/mysite"
#DocumentRoot "/Users/myuser/Sites"
ServerName devel.mysite.com
</VirtualHost>
当我启动 apache 时,我没有收到任何错误或警告,启动时记录的唯一内容是(在/opt/local/apache/logs/error_log
):
[Sat Apr 17 19:56:29 2010] [notice] Digest: generating secret for digest authentication ...
[Sat Apr 17 19:56:29 2010] [notice] Digest: done
[Sat Apr 17 19:56:29 2010] [notice] Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8m DAV/2 configured -- resuming normal operations
几点说明:* /Home/myuser/Sites/mysite 的权限为 755,所有者为 myuser,组为 staff * 其他一切都按预期工作,直到我将 vhost 的 ServerRoot 移动到我家中的目录
答案1
尝试放置与 DocumentRoot 路径匹配的目录标签,如下所示:
<VirtualHost *:80>
DocumentRoot /home/user1/htdocs
ServerName hostname.com
<Directory /home/user1/htdocs>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
答案2
修复了我的 403 禁止错误。我刚刚升级到 10.8 并添加了
<目录 /home/user1/htdocs> 命令允许、拒绝 允许所有人 </目录>