当我试图通过浏览器访问localhost时,我得到这个错误。

AH01630: client denied by server configuration

我检查了我的网站文件夹权限使用:

sudo chmod 777 -R *

这是我的配置文件:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /home/user-name/www/myproject
<Directory />
    Options FollowSymLinks
    AllowOverride all
    Allow from all
</Directory>

<Location />
  Allow from all
  Order Deny,Allow
</Location>

<Directory  /home/user-name/www/myproject/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride all
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride all
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>


当前回答

我还有一个可能对某人有用的。 从PHP 5.6 => 7.0升级后收到相同的错误消息。我们已经更改了PHP上传设置,并且在复制后忘记更改。 尽管我当时没有上传图像,但Silverstripe(我们的CMS)拒绝保存并抛出错误。增加图像上传大小,它直接工作。

其他回答

在花了几个小时后,我自己决定了。

我在vagrant vm中通过cookbook安装Apache/2.4.7 (Ubuntu)。

/etc/apache2/apache2.conf文件默认没有<VirtualHost *:80>元素。

我做了两处改动才完成

added <VirtualHost *:80> 添加 选项索引遵循symlinks AllowOverride所有 允许从所有

最后我启动了vm..

如果跟踪错误日志并重新加载页面,应该会看到有关确切问题的更多信息。

获取环境变量,这样${APACHE_LOG_DIR}将实际工作…

source /etc/apache2/envvars

然后跟在后面看着……

tail -f ${APACHE_LOG_DIR}/error.log

如果你像我一样尝试了上面所有的答案,但都没有帮助,记得检查你的apache2.conf是否有像IncludeOptional conf-enabled/*.conf这样的行,然后检查该文件夹中的每个.conf文件。

我的有一个security.conf文件,其中包括这部分(需要删除/修改,以不阻止我需要运行的.php文件):

<FilesMatch "^(wp-config\.php|php\.ini|php5\.ini|install\.php|php\.info|readme\.md|README\.md|readme\.html|bb-config\.php|\.htaccess|\.htpasswd|readme\.txt|timthumb\.php|error_log|error\.log|PHP_errors\.log|\.sv$
    Require all denied
</FilesMatch>

我不知道这个文件来自哪里,除非在某个时候我掉进了一个兔子洞,试图保护我的apache配置,找到这个conf,添加它,然后完全忘记了它。

这花了我一些摆弄,让这个工作在我自己的FreeBSD服务器运行..

FreeBSD 13 Apache 2.4 Python 3.8 LetsEncrypt

. .但最终我想出了一个可行的VirtualHost:

<VirtualHost *:443>

    ServerName mysite.mydomain.com
    DocumentRoot "/usr/local/www/apache24/data/mysite

    WSGIDaemonProcess mysite python-path=/usr/local/www/apache24/data/mysite/venv/lib/python3.8/site-packages/
    WSGIProcessGroup mysite
    WSGIScriptAlias / /usr/local/www/apache24/data/mysite/core/wsgi.py

    SSLEngine on
    SSLCertificateFile "/usr/local/etc/letsencrypt/live/mysite.mydomain.com/cert.pem"
    SSLCertificateKeyFile "/usr/local/etc/letsencrypt/live/mysite.mydomain.com/privkey.pem"
    SSLCertificateChainFile "/usr/local/etc/letsencrypt/live/mysite.mydomain.com/fullchain.pem"

    <FilesMatch "\.(cgi|shtml|phtml|php|py)$">
        SSLOptions +StdEnvVars
    </FilesMatch>

    BrowserMatch "MSIE [2-5]" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0

    CustomLog "/usr/local/www/apache24/data/mysite/log/py-ssl.log" \
        "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    CustomLog "/usr/local/www/apache24/data/mysite/log/py-access.log" combined
    ErrorLog "/usr/local/www/apache24/data/mysite/log/py-error.log"

    <Directory "/usr/local/www/apache24/data/mysite">
        AllowOverride All
        Options +ExecCGI
        Require all granted
        Allow from all
    </Directory

</VirtualHost>

为了帮助像我一样在谷歌上搜索的人,我在试图访问服务器上的SVG文件时遇到了这个错误消息,例如https://example.com/images/file.svg。其他文件类型似乎还好,只是SVG失败了。

我在/etc/httpd conf文件中寻找,并检查了每一个要求所有拒绝类型的配置,只是找不到什么配置有这种效果。

我在VirtualHost配置中将LogLevel转换为调试,可以看到mod_authz_core日志指定有一个'Require all denied'的效果:

[Mon Jun 10 13:09:54.321022 2019] [authz_core:debug] [pid 23459:tid 140576341206784] mod_authz_core.c(817): [client 127.0.0.1:54626] AH01626: authorization result of Require all denied: denied
[Mon Jun 10 13:09:54.321038 2019] [authz_core:debug] [pid 23459:tid 140576341206784] mod_authz_core.c(817): [client 127.0.0.1:54626] AH01626: authorization result of <RequireAny>: denied
[Mon Jun 10 13:09:54.321082 2019] [authz_core:error] [pid 23459:tid 140576341206784] [client 127.0.0.1:54626] AH01630: client denied by server configuration: /home/blah/htdocs/images/file.svg

通过盲测,我将文件移动到web根目录的根目录,然后发现我可以在https://example.com/file.svg上访问它。所以它只在images文件夹失败了。这让我在images文件夹中找到了一个我完全不知道的。htaccess文件。

原来禅宗车1.5带有一个图像/。Htaccess文件有:

# deny *everything*
 <FilesMatch ".*">
   <IfModule mod_authz_core.c>
     Require all denied
   </IfModule>
   <IfModule !mod_authz_core.c>
     Order Allow,Deny
     Deny from all
   </IfModule>
 </FilesMatch>

 # but now allow just *certain* necessary files:
 <FilesMatch "(?i).*\.(jpe?g|gif|webp|png|swf)$" >
   <IfModule mod_authz_core.c>
     Require all granted
   </IfModule>
   <IfModule !mod_authz_core.c>
     Order Allow,Deny
     Allow from all
   </IfModule>
 </FilesMatch>

这是非常恼人的,我希望这可以提醒其他人检查文件系统的每一个级别的.htaccess文件,导致你有问题访问的文件,以防有这种tom愚行正在发生。