About Apache server access control

  
        

Apache's access control refers to any way of access control of any resource.

First, host or IP address based control

This access control is based on the visitor's host name or IP address, by using the Deny and Allow instructions to allow or prohibit access to a host Our server resources. Usually the Order directive is also used together to define the order in which the Deny and Allows directives work. If you do not use the Order directive, the default order is Deny, Allow, which is equivalent to Order Deny, Allow.

The Order directive works in conjunction with the Allow, Deny directive to implement a three-step control system.

Step 1: According to the order of the Order, apply all the Allow commands or Deny commands in the order to the current request; that is, if it is Order allow, deny, then the first step is to put all the The Allow directive is applied to the current access, if there is a match, then the access is allowed; if there is no match to an Allow directive, then access is prohibited;

Step 2: All the remaining instructions are all The statement matches the current request, and if there is a match, the corresponding access control is executed;

Step 3: If the current request does not match any of the first two steps, the next instruction in the Order instruction is executed.

Below, an example to understand:

Make the resources in the specified directory only local access

 <Directory "/server"> Order allow, deny Allow from 127.0.0.1 </Directory> Step 1: The local access matches the Allow from 127.0.0.1 command, so it is allowed; other hosts do not match any of the Allow commands, so access is forbidden; 

Step 2: All accesses do not match the Deny instruction;

Step 3: There is no access to any instruction, that is, it is not a local access. Follow the Order instruction to execute the following deny instructions. Therefore, access is forbidden;

Second, access control according to environment variables

This method can be implemented by Allow from env= or Deny from env= syntax, for example, only Firefox browser is allowed. Customer Access:

 <Directory "/server"> SetEnvIf User-Agent "Firefox" ff=1 Order allow,deny Allow from env=ff </Directory> Access control with mod_rewrite 

With the [F] flag of the mod_rewrite directive, access control can be implemented on a resource based on any criteria.

For example, I want to access any resource from 8 am to 6 pm, I can do this:

RewriteEngine OnRewriteCond %{TIME_HOUR} >20 [OR]RewriteCond %{ TIME_HOUR} <07RewriteRule ^/fridge - [F] In this case, it will return to 403 after 8:00 in the evening until 7 am.
Copyright © Windows knowledge All Rights Reserved