client denied by server configuration 解决办法

在安装试用 nagiosql 时发现的问题,当时根据网上的N多教程和官方文档的介绍,我的虚拟目录是这样配置的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Alias /nagiosql "/usr/local/nagios/nagiosql"

<directory "/usr/local/nagios/nagiosql">
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
# AuthName "NagiosQL Access"
# AuthType Basic
# AuthUserFile /etc/nagiosql/auth/nagiosql.users
# Require valid-user
</directory>

按理说只要目录权限没问题, nagiosql 是可以被访问的,但是重启 apache 后,访问 http://IP/nagiosql 出现 403 错误,也就是权限错误。按照思路去研究了半天的权限设置,最后逼不得已把 nagiosql 目录设定成 chmod -R 777 ,可问题依旧。

最后静下心来看日志,发现存在 AH01630: client denied by server configuration 的报错。上网查了资料才发现,原来这是 apache2.2 和 apache2.4 的配置写法不同导致,在 apache2.4 里,用 Require all granted 代替 Allow from all 才能让配置生效。根据测试发现, Require all grantedAllow from all 同时存在并不会相互影响,所以虚拟目录配置应当改成:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Alias /nagiosql "/usr/local/nagios/nagiosql"

<directory "/usr/local/nagios/nagiosql">
Options None
AllowOverride None
Require all granted #新增
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
# AuthName "NagiosQL Access"
# AuthType Basic
# AuthUserFile /etc/nagiosql/auth/nagiosql.users
# Require valid-user
</directory>

重启 apache 后,访问正常,问题解决。