68

今天我更新了Ubuntu 服务器 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.

我应该怎么解决?

4

11 回答 11

115

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

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

Order Deny,Allow
Deny from all

Require all granted

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

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

于 2013-10-18T14:18:08.353 回答
40

我在新安装 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>
于 2014-04-10T23:34:28.033 回答
22

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

对我来说,它有助于为<Directory>错误日志抱怨的每个路径添加一个额外的 -entry 并用Require all granted.

所以在你的情况下你可以试试

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

我不得不将我的配置文件从一个文件夹移动到另一个文件conf.dsites-enabled

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

于 2013-10-18T22:36:16.777 回答
20

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

<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>
于 2013-11-24T23:59:10.687 回答
9

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

例如:

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

这适用于Ubuntu 14.04 (Trusty Tahr)。

于 2014-07-03T12:41:00.283 回答
8

您的虚拟主机文件名应该是 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
于 2013-12-22T12:45:33.563 回答
3

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

<Directory>

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

正如 Jan Czarny 所建议和 user3801675 所建议的那样,是解决此问题的最安全方法。

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

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

于 2015-02-08T18:02:19.813 回答
1

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

我的主要 DocumentRoot 是默认值 /var/www/html ,并且在我使用的 VirtualHost 上/sites/example.com

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

它就像一个魅力。

于 2015-07-21T20:42:17.080 回答
0

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

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

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

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

现在它工作正常。

于 2019-04-07T20:53:44.390 回答
0

我的 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>
于 2019-05-17T10:07:34.063 回答
-3

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

3个小时后把我的头发扯掉了......

于 2013-12-03T06:10:59.597 回答