【问题标题】:Apache 2.4.6 on Ubuntu Server: Client denied by server configuration (PHP FPM) [While loading PHP file]Ubuntu Server 上的 Apache 2.4.6:客户端被服务器配置拒绝 (PHP FPM) [加载 PHP 文件时]
【发布时间】:2013-10-27 01:30:06
【问题描述】:

今天我更新了Ubuntu server 13.04 (Raring Ringtail) → 13.10 (Saucy Salamander)。

我的 Apache 2 安装坏了。

这是我的配置:

文件error.log

[Fri Oct 18 10:48:07.237170 2013] [:notice] [pid 8292:tid 139804677900160] FastCGI: process manager initialized (pid 8292)
[Fri Oct 18 10:48:07.241185 2013] [mpm_event:notice] [pid 8289:tid 139804677900160] AH00489: Apache/2.4.6 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 configured -- resuming normal operations
[Fri Oct 18 10:48:07.241652 2013] [core:notice] [pid 8289:tid 139804677900160] AH00094: Command line: '/usr/sbin/apache2'
[Fri Oct 18 10:48:28.313923 2013] [authz_core:error] [pid 8294:tid 139804573181696]   [client 81.219.59.75:3536] AH01630: client denied by server configuration: /usr/lib/cgi-bin/php5-fcgi

文件default.conf

#EU
<VirtualHost *:80>
    #ServerName
    DocumentRoot /var/www/dev_stable

    DirectoryIndex index.php index.html index.htm

    <Directory /var/www/dev_stable>
          Options Indexes FollowSymLinks MultiViews

          AllowOverride all
          Require all granted
    </Directory>
</VirtualHost>

文件mods-enabled/fastcgi.conf

#<IfModule mod_fastcgi.c>
#  AddHandler fastcgi-script .fcgi
# FastCgiWrapper /usr/lib/apache2/suexec
#  FastCgiIpcDir /var/lib/apache2/fastcgi
#</IfModule>


<IfModule mod_fastcgi.c>
    AddHandler php5-fcgi .php
    Action php5-fcgi /php5-fcgi
    Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
    FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
</Ifmodule>

当我尝试通过浏览器加载文件时:

site_name/TEST/

Forbidden

You don't have permission to access /php5-fcgi/TEST/index.php on this server.

我应该怎么解决?

【问题讨论】:

标签: apache ubuntu php


【解决方案1】:

我的 httpd.conf 中有以下配置拒绝从 wordpress 执行 wpadmin/setup-config.php 文件。删除 |-config 部分解决了这个问题。 我认为这个 httpd.conf 来自 plesk,但它可能是来自 wordpress 的一些默认建议配置,我不知道。无论如何,我可以在设置完成后安全地添加它。

<LocationMatch "(?i:(?:wp-config\\.bak|\\.wp-config\\.php\\.swp|(?:readme|license|changelog|-config|-sample)\\.(?:php|md|txt|htm|html)))">
                        Require all denied
                </LocationMatch>

【讨论】:

    【解决方案2】:

    升级系统后我遇到了同样的问题。 就我而言,问题是由加载配置文件的顺序引起的。 在/etc/httpd/httpd.confinitally 中定义如下:

    IncludeOptional conf.d/*.conf
    IncludeOptional sites-enabled/*.conf
    

    经过几个小时的尝试,我尝试了以下顺序:

    IncludeOptional sites-enabled/*.conf
    IncludeOptional conf.d/*.conf
    

    现在可以正常使用了。

    【讨论】:

      【解决方案3】:

      apache2.conf 中,替换或删除 AllowOverride None Require all denied ,就像 Jan Czarny 建议的那样。

      例如:

      <Directory />
          Options FollowSymLinks
          AllowOverride None
          #Require all denied
          Require all granted
      </Directory>
      

      这在 Ubuntu 14.04 (Trusty Tahr) 有效。

      【讨论】:

      • 升级到 Ubunto 14.04 后,这让我很震惊......谢谢。
      • 这会影响安全吗?
      【解决方案4】:

      我在新安装 Apache 2.4 时遇到了这个确切的问题。经过几个小时的谷歌搜索和测试,我终于发现我还必须允许访问包含 Alias 指令的(不存在的)目标的目录。也就是说,这对我有用:

      # File: /etc/apache2/conf-available/php5-fpm.conf
      <IfModule mod_fastcgi.c>
          AddHandler php5-fcgi .php
          Action php5-fcgi /php5-fcgi
          Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
          FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
      
          # NOTE: using '/usr/lib/cgi-bin/php5-cgi' here does not work,
          #   it doesn't exist in the filesystem!
          <Directory /usr/lib/cgi-bin>
              Require all granted
          </Directory>
      </Ifmodule>
      

      【讨论】:

      • 值得注意的是,我将整个 php5-fpm.conf 切换到上面的那个来让我的工作,而不是仅仅添加到目录部分。
      • 为cgi-bin添加&lt;Directory&gt;标签解决了我的问题!
      • 谢谢@whyscream,这解决了我的问题。实际上,这个目录授权是在 serve-cgi-bin.conf 中定义的,但只有在启用 cgi.load 时才会加载!我将通过添加来自 serve-cgi-bin.conf 的定义来改进解决方案:` AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Require all grant `
      【解决方案5】:

      我今天遇到了类似的问题(但mod_wsgi)。这可能是 Apache 2.2 到 2.4 的问题。可以在here 找到完整的更改列表。

      对我来说,它有助于为错误日志抱怨的每个路径添加一个额外的 &lt;Directory&gt;-entry 并用 Require all granted 填充该部分。

      所以你可以试试

      <Directory /usr/lib/cgi-bin/php5-fcgi>
          Require all granted
          Options FollowSymLinks
      </Directory>
      

      我不得不将我的配置文件从文件夹 conf.d 移动到文件夹 sites-enabled

      总而言之,这对我有用,但我不保证它也适用于你的情况。

      【讨论】:

      • +1 链接到 Apache 2.2->2.4 更改列表。这应该是每个即将升级的人的必读内容。
      • 那进入什么文件? /etc/apache2/apache2.conf? /etc/apache2/mods-enabled/ 中的某个文件?其他地方?
      【解决方案6】:

      我也有同样的问题。我在本地机器上运行了几个虚拟主机进行开发。

      首先,我更改了/etc/apache2/conf-available/php5-fpm.conf。我更换了每个

      Order Deny,Allow
      Deny from all
      

      Require all granted
      

      配置必须由a2enconf php5-fpm 启用。我对我的虚拟主机配置做了同样的事情并进行了替换。

      我认为出于安全原因不建议这样做,但只要我将我的服务器用于本地目的,我就可以忍受它。

      【讨论】:

      • 在 apache2.conf -> 替换或删除&lt;Directory /&gt; AllowOverride none Require all denied &lt;/Directory&gt;
      【解决方案7】:

      我只是得到了这个错误,因为我使用了一个完全不同的 DocumentRoot 目录。

      我的主 DocumentRoot 是默认的 /var/www/html 在 VirtualHost 上我使用了/sites/example.com

      我在/var/www/html/example.com(到/sites/example.com)上创建了一个链接。 DocumentRoot 设置为/var/www/html/example.com

      它就像一个魅力。

      【讨论】:

        【解决方案8】:

        我不认为在此指令中将“要求全部拒绝”替换为“要求全部授予”:

        <Directory>
        
            Options FollowSymLinks
            AllowOverride None
            #Require all denied
            Require all granted
        </Directory>
        

        由 Jan Czarny 建议并由 user3801675 提出是解决此问题的最安全方法。

        根据 Apache 配置文件,该行拒绝访问整个服务器文件系统。替换它可能确实允许访问您的虚拟主机文件夹,但代价是允许访问您的整个计算机!

        Gev Balyan 的方法似乎是这里最安全的方法。这是今天早上设置新的 Apache 服务器后困扰我的“拒绝访问问题”的答案。

        【讨论】:

        • 这不是答案,而是评论。
        【解决方案9】:

        您的虚拟主机文件名应该是 mysite.com.conf 并且应该包含此信息

        <VirtualHost *:80>
            # The ServerName directive sets the request scheme, hostname and port that
            # the server uses to identify itself. This is used when creating
            # redirection URLs. In the context of virtual hosts, the ServerName
            # specifies what hostname must appear in the request's Host: header to
            # match this virtual host. For the default virtual host (this file) this
            # value is not decisive as it is used as a last resort host regardless.
            # However, you must set it for any further virtual host explicitly.
            ServerName mysite.com
            ServerAlias www.mysite.com
        
            ServerAdmin info@mysite.com
            DocumentRoot /var/www/mysite
        
            # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
            # error, crit, alert, emerg.
            # It is also possible to configure the loglevel for particular
            # modules, e.g.
            #LogLevel info ssl:warn
        
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
        
        <Directory "/var/www/mysite">
        Options All
        AllowOverride All
        Require all granted
        </Directory>
        
        
            # For most configuration files from conf-available/, which are
            # enabled or disabled at a global level, it is possible to
            # include a line for only one particular virtual host. For example the
            # following line enables the CGI configuration for this host only
            # after it has been globally disabled with "a2disconf".
            #Include conf-available/serve-cgi-bin.conf
        </VirtualHost>
        
        # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
        

        【讨论】:

          【解决方案10】:

          对于那些使用 AWS(亚马逊网络服务)的人,请记住将您的 SSL 端口(在我的例子中为 443)的规则添加到您的安全组。我收到此错误是因为我忘记打开端口。

          3 小时后把我的头发扯下来......

          【讨论】:

          • 此答案与此错误消息完全无关。
          【解决方案11】:

          我最近遇到了同样的问题。我必须从以下位置更改我的虚拟主机:

          <VirtualHost *:80>
            ServerName local.example.com
          
            DocumentRoot /home/example/public
          
            <Directory />
              Order allow,deny
              Allow from all
            </Directory>
          </VirtualHost>
          

          收件人:

          <VirtualHost *:80>
            ServerName local.example.com
          
            DocumentRoot /home/example/public
          
            <Directory />
              Options All
              AllowOverride All
              Require all granted
            </Directory>
          </VirtualHost>
          

          【讨论】:

          • 漂亮,将一堆域从 2.2 服务器转移到 2.4 服务器并保留 vhost.conf 文件以节省时间.. 全部更改为此并修复了所有问题。非常感谢
          • 非常感谢。这有助于我在 Windows 10 上使用 xampp 5.6
          猜你喜欢
          • 2012-05-08
          相关资源
          最近更新 更多