apache 2.4 访问权限配置

来源:互联网 发布:丽江知乎 编辑:程序博客网 时间:2024/06/07 08:55
在apache 2.4里,访问权限配置与2.2不同,如果设置不对,则会报403错误,日志中会报 AH01630: client denied by server configuration。

[Sun Aug 27 19:01:37.591240 2017] [authz_core:error] [pid 16] [client 172.17.0.1:55766] AH01630: client denied by server configuration: /var/www/html/doc/
172.17.0.1 - - [27/Aug/2017:19:01:37 +0800] "GET /doc/ HTTP/1.1" 403 506 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"

1、如果目录下有.htaccess文件,并且有如下内容,则此目录外部不能访问。
## no access to this folder

# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
</IfModule>

# Apache 2.2
<IfModule !mod_authz_core.c>
Order Allow,Deny
Deny from all
</IfModule>

可将Require all denied修改为Require all granted允许外部访问,或修改为Require host localhost只允许本机访问,或修改为Require ip x.x.x.x 允许指定的IP访问。
如将mantisbt的doc可在本地访问,可修改doc目录下的.htaccess文件。
1)如果是本机安装,可将Require all denied修改为Require ip 127.0.0.1
2)如果是安装在docker下,可将Require all denied修改为Require ip 172.17.0.1
具体看日志中报错的client ip 地址。
2、如果放开指定目录的访问权限,也可在virtualhost的directory配置中明确设定Require all granted。
<Directory /var/www/html>
Options -Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
更多配置选项见https://httpd.apache.org/docs/2.4/mod/mod_authz_core.html#require