问题描述
今天,我更新了Ubuntu server 13.04(竞赛环尾)→13.10(Saucy am)。
我的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.
我该怎么解决?
最佳方案
我有完全一样的问题。我在本地计算机上运行了两个虚拟主机以进行开发。
首先,我更改了/etc/apache2/conf-available/php5-fpm.conf
。我更换了每个
Order Deny,Allow
Deny from all
至
Require all granted
必须通过a2enconf php5-fpm
启用配置。我对虚拟主机配置进行了相同的操作,并进行了替换。
我认为出于安全原因不建议这样做,但是只要我将服务器用于本地目的,就可以使用它。
次佳方案
我在安装新的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>
第三种方案
我今天遇到了类似的问题(但使用mod_wsgi
)。这可能是Apache 2.2到2.4的问题。完整的更改列表可在here中找到。
对我来说,这有助于为error-log抱怨的每个路径添加一个额外的<Directory>
-条目,并用Require all granted
填充该部分。
因此,您可以尝试
<Directory /usr/lib/cgi-bin/php5-fcgi>
Require all granted
Options FollowSymLinks
</Directory>
并且我不得不将配置文件从文件夹conf.d
移到文件夹sites-enabled
。
总而言之,这对我来说是成功的诀窍,但我不保证它也可以在您的情况下使用。
第四种方案
我最近遇到了同样的问题。我必须从以下位置更改虚拟主机:
<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>
第五种方案
在apache2.conf
中,替换或删除<目录/> AllowOverride无要求所有拒绝的< /Directory> ;,如建议的Jan Czarny。
例如:
<Directory />
Options FollowSymLinks
AllowOverride None
#Require all denied
Require all granted
</Directory>
这在Ubuntu 14.04(Trusty Tahr)中有效。
第六种方案
您的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
第七种方案
我不认为在此指令中将“需要全部拒绝”替换为“需要全部授予”:
<Directory>
Options FollowSymLinks
AllowOverride None
#Require all denied
Require all granted
</Directory>
由Jan Czarny建议并由user3801675取代是解决此问题的最安全方法。
根据Apache配置文件,该行拒绝访问服务器的整个文件系统。替换它可能确实允许访问您的虚拟主机文件夹,但代价是也允许访问您的整个计算机!
Gev Balyan的方法似乎是这里最安全的方法。这是今天早上设置新Apache服务器后困扰我的“访问被拒绝问题”的答案。