【问题标题】:XAMPP (Mac) Virtual host showing 403XAMPP (Mac) 虚拟主机显示 403
【发布时间】:2013-08-24 07:14:18
【问题描述】:

当我尝试在我的 MAC 上运行 XAMPP 安装时,我不断收到 Access Forbidden Error 403

我在/Applications/XAMPP/htdocs 之外运行该项目。它在我的/Users/my_user_name/Projects/ 目录中。

每次我尝试访问我的虚拟主机时都会收到 403 错误:禁止访问。

我已经编辑了我的 httpd-vhosts.conf 文件,并且我在 httpd.conf 中允许了虚拟主机。

我还在 httpd.conf 中将 User 和 Group 设置为 User my_user_name 和 Group Admin

我什至尝试对我的所有文件和目录 777 进行 chmod,但我仍然被禁止访问。

我还在新安全设置的 httpd-xampp.conf 文件中将拒绝更改为允许。

XAMPP 提供的 erro_log 没有提到 403 错误,我确实在访问日志中看到它为 127.0.0.1 - - [21/Aug/2013:14:45:20 -0400] "GET / HTTP/1.1" 403 1034

我打开了错误,我看到了这个 [authz_core:error] [pid 52813] [client 127.0.0.1:57473] AH01630: client denied by server configuration:

不确定还有什么要检查或尝试的。请帮助大声笑。

【问题讨论】:

    标签: macos apache xampp virtualhost


    【解决方案1】:

    只想在这里得到答案: 您可以通过在 httpd-vhosts.conf 中将 Require all granted 添加到每个 VirtualHost 来允许访问:

    # VirtualHost for my.site.com
    <VirtualHost *:80>
        ServerAdmin webmaster@site.com
        DocumentRoot "/Users/me/www/my.site.com/"
        ServerName my.site.com
        <Directory "/Users/me/www/my.site.com">
            ServerSignature Off
            Options Indexes FollowSymLinks IncludesNoExec
            AllowOverride All
    
            #Order allow,deny  <- You can remove this
            #Allow from all    <- and that
    
            # Insert the following:
            Require all granted
    
        </Directory>
    </VirtualHost>
    

    祝你好运!

    【讨论】:

    • 这是正确的方法。请记住,您还必须删除 http-vhosts.conf 中的所有垃圾示例代码
    • 您能分享我必须更新此代码的文件路径吗?
    【解决方案2】:

    我一直遇到这个 403 问题,直到...

    我的 vhosts 文件中的卷曲(左右)引号。

    如果您在错误日志中看到类似“xe2\x80\x9c”的内容,那么这就是您的问题。

    我在可靠的编辑器(我使用 Dreamweaver)中打开了 httpd-vhosts.conf 文件,并注意到引号是卷曲的(左引号和右引号)。它们必须是直引号。我 Mac 上的常规文本编辑器会自动更改我对这些卷曲引号所做的任何引号,而我没有注意到它。

    希望这个答案会对某人有所帮助。

    【讨论】:

    • 谢谢!一直在拉我的头发。事实证明,OSX 的 TextEdit 在关闭字符串时会自动将 ASCII 引号更改为右引号。避免使用 Apple 工具的另一个原因...
    • 你是超级明星!!!我一直试图让虚拟主机在 Mac 上毫无乐趣地工作数小时。我终于看到了这条评论(它应该是“而不是”在 http-vhosts.con 文件中使用,但是 TextEdit 将“改回”而不显示它已经完成了!!!!)谢谢
    【解决方案3】:

    在我的情况下,问题在于用户定义 httpd.conf 适用于 Windows:

    User daemon
    Group daemon
    

    改为

    User myusername
    

    成功了

    对于 Linux:

    User myusername
    Group sudo
    

    对于 OSX:

    User myusername
    Group admin
    

    您可能还需要设置文件夹的权限

    sudo chown -R yourusername /Applications/XAMPP/xamppfiles/htdocs
    

    【讨论】:

    • 这不是必需的。确保双引号不是卷曲的 “” -> "" 并且缺少 require all granted 对我有用。对于 OSX,我将用户和组都保留为 daemon。当我什至只更改用户时,我的正常本地主机在我的代码中有 403 errors 和几行 require_once
    【解决方案4】:

    我在以下链接中发现了一些实际上解决了我的问题的东西。我希望这可以节省一些人拔头发的时间。哈哈

    http://www.apachefriends.org/f/viewtopic.php?p=198815&sid=35790f5d017f27c93c1fd4d260b35128

    【讨论】:

    • TL;该链接的 DR - 添加带有 Require all granted&lt;Directory... 块,就像 @AvL 建议的那样
    • 死链接。相关内容应该已经复制到这里了。
    【解决方案5】:

    我收到此错误是因为我忘记将“DocumentRoot”网址和“目录”网址设置为相同。

    #dl local
    <VirtualHost *:80>
        ServerName dl.local
        DocumentRoot "/Users/myuser/dl_live"               <<< ----- This URL has to match
        <Directory "/Users/myuser/dl_live">                <<< ----- this URL
            Options Indexes FollowSymLinks IncludesNoExec
            AllowOverride All
            Require all granted
        </Directory>
        ErrorLog "logs/dl.local_error_log"
    </VirtualHost>
    

    如果您这样做,您可能会在错误日志文件中看到如下错误:

    [Tue Feb 03 13:50:26.189944 2015] [authz_core:error] [pid 25254] [client 127.0.0.1:54841] AH01630: client denied by server configuration: /Users/myUsername/path/to_local/virtual_host/
    

    【讨论】:

      【解决方案6】:

      我通过删除 httpd-vhosts.conf 中的标准虚拟主机解决了这个问题 并且只留下您想要的虚拟主机配置。

      【讨论】: