Ubuntu Server上的Apache 2.4.6:服务器配置拒绝客户端(PHP FPM)[加载PHP文件时]

Jan*_*rny 68 php apache ubuntu

今天我更新了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
Run Code Online (Sandbox Code Playgroud)

文件 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>
Run Code Online (Sandbox Code Playgroud)

文件 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>
Run Code Online (Sandbox Code Playgroud)

当我尝试通过浏览器加载文件时,我得到了:

site_name/TEST/

Forbidden

You don't have permission to access /php5-fcgi/TEST/index.php on this server.
Run Code Online (Sandbox Code Playgroud)

我该怎么办呢?

小智 113

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

首先,我改变了/etc/apache2/conf-available/php5-fpm.conf.我取代了每一个

Order Deny,Allow
Deny from all
Run Code Online (Sandbox Code Playgroud)

Require all granted
Run Code Online (Sandbox Code Playgroud)

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

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

  • 在apache2.conf中 - >替换或删除`<Directory /> AllowOverride none要求全部拒绝</ Directory>` (21认同)

why*_*eam 39

我在新安装的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>
Run Code Online (Sandbox Code Playgroud)


OBu*_*OBu 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>
Run Code Online (Sandbox Code Playgroud)

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

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

  • +1为Apache 2.2-> 2.4更改列表的链接.对于每个即将升级的人来说,这应该是必读的. (3认同)

Luk*_*uke 20

我最近遇到了同样的问题.我不得不改变我的虚拟主机:

<VirtualHost *:80>
  ServerName local.example.com

  DocumentRoot /home/example/public

  <Directory />
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

至:

<VirtualHost *:80>
  ServerName local.example.com

  DocumentRoot /home/example/public

  <Directory />
    Options All
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

  • 从2.2升级到2.4,这就是诀窍. (2认同)

小智 9

apache2.conf,替换或删除<Directory /> AllowOverride无需要全部拒绝</ Directory>,如建议的Jan Czarny.

例如:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    #Require all denied
    Require all granted
</Directory>
Run Code Online (Sandbox Code Playgroud)

这适用于Ubuntu 14.04(Trusty Tahr).


Gev*_*yan 7

您的virtualhost文件名应为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
Run Code Online (Sandbox Code Playgroud)