09 Jan 2015
模块:mod_access_compat
简介:
在新版本中被mod_authz_host替代
可用在<Directory><Files><Location>和.htaccess文件中
可控制hostname,IP或者request的变量
用Allow和Deny来控制客户端的访问权限
用Order来设置默认访问状态,和设定Allow、Deny的生效顺序
用法简介:
Allow用法汇总:
Allow from example.org
Allow from .net example.edu
Allow from 10.1.2.3
Allow from 192.168.1.104 192.168.1.205
Allow from 10.1
Allow from 10 172.20 192.168.2
Allow from 10.1.0.0/255.255.0.0
Allow from 10.1.0.0/16
Allow from env=env-variable
Allow from env=!env-variable
举例 - 只有user-agent是knockknock/2.0的才可以访问
SetEnvIf User-Agent ^KnockKnock/2\.0 let_me_in
<Directory "/docroot">
Order Deny,Allow
Deny from all
Allow from env=let_me_in
</Directory>
Deny用法汇总: 同Allow,只是关键词变成了Deny
Order用法汇总:
Order Allow,Deny
a. 判断所有Allow条件,匹配任意一条则通过,若无匹配,则拒绝;
b. 判断所有Deny条件,匹配任意一条则拒绝;
c. 以上均无匹配的,默认拒绝。
Order Deny,Allow
a. 判断所有Deny条件,匹配任意一条则拒绝,除非它同时匹配Allow规则
b. 判断所有Allow条件,匹配任意一条则通过;
c. 以上均无匹配的,默认通过
举例说明
******************************************************* Order Deny,Allow Allow from example.org Deny from foo.example.org ******************************************************* a. foo.example.org匹配Deny,但同时满足Allow,通过 b. example.org匹配Allow,通过 c. 其他所有不匹配*.example.org的,通过 综述,所有条件的域名均可通过以上规则 ## 实例 ## 只允许本机访问特定目录下的php文件 ******************************************************* <Directory /path/to/dir> php_admin_flag engine off <Filesmatch "(.*)php$"> Order deny,allow Deny from all Allow from 127.0.0.1 </Filesmatch> </Directory> *******************************************************
作用:检查是否用户被authorization provider授权
模块:mod_authz_core
语法:Require [not] entity-name [entity-name] ...
container: <RequireAll>, <RequireAny> and <RequireNone>
authorization provider汇总:
Require all granted
Access is allowed unconditionallyRequire all denied
Access is denied unconditionallyRequire env env-var [env-var] ...
Access is allowed only if one of the given environment variables is setRequire method http-method [http-method] ...
Access is allowed only for the given HTTP methodsRequire expr expression
Access is allowed if expression evaluates to true 示例:
Require expr "%{TIME_HOUR} -ge 9 && %{TIME_HOUR} -le 17"由
mod_authz_user,mod_authz_host,mod_authz_groupfile提供的用法
Require user userid [userid] ...
Only the named users can access the resource.Require group group-name [group-name] ...
Only users in the named groups can access the resource.Require valid-user
All valid users can access the resource.Require ip 10 172.20 192.168.2
Clients in the specified IP address ranges can access the resource.
用法举例:
## env:允许KnockKnoick/2.0开头的User-Agent访问 SetEnvIf User-Agent ^KnockKnock/2\.0 let_me_in <Directory "/docroot"> Require env let_me_in </Directory> ## expr: Require expr "%{TIME_HOUR} -ge 9 && %{TIME_HOUR} -le 17" # 以下两种同义 <RequireAll> Require expr "!(%{QUERY_STRING} =~ /secret/)" Require expr "%{REQUEST_URI} in { '/example.cgi', '/other.cgi' }" </RequireAll> Require expr "!(%{QUERY_STRING} =~ /secret/) && %{REQUEST_URI} in { '/example.cgi', '/other.cgi' }"