【问题标题】:apache set virtual host access 403 access forbidden,why?apache设置虚拟主机访问403访问被禁止,为什么?
【发布时间】:2015-09-16 16:59:47
【问题描述】:

环境是 OS X 10.10.2 Yosemite,我正在运行 XAMPP 服务器。 我的配置:

httpd.conf

<Directory />
    #Options FollowSymLinks
    #Require all granted
    AllowOverride All
    #XAMPP
    Order deny,allow
    Allow from all
</Directory>
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
    Options Indexes FollowSymLinks ExecCGI Includes
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
</Directory>
# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin luckyyulin@sina.cn
    DocumentRoot "/Applications/XAMPP/htdocs/makefriend99/1"
    ServerName makefriend99.com
    ServerAlias www.makefriend99.com
    ErrorLog "logs/makefriend99/error_log"
    CustomLog "logs/makefriend99/access_log" common
    <Directory /Applications/XAMPP/htdocs/makefriend99/1>
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin luckyyulin@sina.cn
    DocumentRoot "/Applications/XAMPP/htdocs/angular"
    ServerName ngaction.com
    ServerAlias www.ngaction.com
    ErrorLog "logs/angular/error_log"
    CustomLog "logs/angular/access_log" common
    <Directory /Applications/XAMPP/htdocs/angular>
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

主机

127.0.0.1 makefriend99.com
127.0.0.1 ngaction.com

我在添加ngation.com之前访问makefriend99.com是成功的,除了localhost/makefriend99/1。但是访问ngation.com、localhost/makefriend99/1和403访问的localhost/angular都失败了 添加ngaction.com后禁止,makefriend99.com成功,访问localhost到makefriend99.com。 试了网上看到的一些方法,都没有解决问题,谁能帮我解释一下原因并给出解决办法?

【问题讨论】:

  • 我也想知道这个问题的答案,如果你找到了请告诉我。
  • 我在本地主机和 apache 上遇到了这个问题。我最终更改了根中 WebServer 的权限以获得访问权限。 serverfault.com/questions/357108/…
  • @5ervant 我很高兴
  • @WillCampbell 如何在 root 中更改 webserver 的权限?我已经修改了访问目录,但是没有用。

标签: php apache virtualhost


【解决方案1】:
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>

【讨论】:

    【解决方案2】:

    尝试通过将Require all granted 指令添加到特定的VirtualHost Directory 来允许访问如何?

            ...
            #Order deny,allow    <- You can try to remove this
            #Allow from all      <- and that if they're just a crap.
            Require all granted
        </Directory>
    </VirtualHost>
    

    【讨论】:

      【解决方案3】:

      首先,这个问题可以回答它:https://stackoverflow.com/a/24665604/3990714 和这个:https://stackoverflow.com/a/9117898/3990714

      如果第一个不起作用,试试这个:

      [注意:我不使用 XAMPP,因此这一步可能无关紧要,您可能希望自定义 CHMOD 您 XAMPP 文件中的所有子目录]: 在某个地方,Apple 移动了 Apache WebServer 文件夹,并且出现了一堆权限错误,导致 403 Access Forbidden Error(包括我在内)。

      我的本​​地主机特别遇到了这个问题,但我认为这里的概念是相同的。

      在您的终端中: 通过以下方式转到主目录:

      $ cd 
      

      然后我们将向上爬目录树。

      $ cd ../../ 
      

      进入 Macintosh HD 磁盘(根目录)。 那么:

      $ cd Library 
      

      如果您键入ls 命令,您应该会看到所有内容。然后从之前的链接(见here)chmod 到WebServer 文件夹。您可能还必须对该文件夹中的所有子目录进行 chmod,但是当我遇到此错误时,我没有遇到该问题。

      【讨论】:

      • 非常感谢,第一个问题的答案解决了我的问题,导航 ngaction.com 可以访问我的网站,但我不知道为什么导航 localhost 访问其中一个虚拟主机(makefriend99.com),你能帮帮我吗?
      • @5ervant 第一个问题解决了我的问题,你可以试试。
      【解决方案4】:

      我明白了,它们都在同一个 IP 上运行。如果它们也在同一个端口上运行,则必须更改其中一个的端口。

      【讨论】:

        猜你喜欢
        • 2015-09-16
        • 2012-02-11
        • 2017-09-07
        • 2016-11-06
        • 2014-02-03
        • 2015-05-24
        • 2012-11-04
        • 2016-08-05
        • 1970-01-01
        相关资源
        最近更新 更多