The mod_authz_host module in Apache is used to make authorization decisions based on hostname or IP address. Here’s how you can configure it.
Firstly, ensure that you have the mod_authz_host module installed and enabled within your Apache server. You can check this by running the following command:
```
$ apachectl -M | grep authz_host_module
```
If the module is installed and enabled, this will return “authz_host_module (shared)”.
1. Use Order, Allow, and Deny Directives
One of the most basic use cases of the mod_authz_host module is allowing or denying access to a site or directory based on IP address.
Here’s an example of how to deny access to a directory for everyone except a specific IP address.
```
```
In the above example, the Order directive is used to set the order of processing the Allow and Deny statements. “deny,allow” means that the Deny directives are evaluated before the Allow ones.
The Deny from all directive will block access for everyone, and then the Allow from directive will allow access from the listed IP address.
1. Use the Require directive (For Apache 2.4 and later)
The Order, Allow, and Deny directives have been deprecated starting from Apache 2.4. You should now use the Require directive.
Here’s an example of how to deny access to a directory for everyone except a specific IP address.
```
```
In the above example, the Require directive is used to allow access from just the listed IP address. All other IP addresses will be denied access.
After making changes to the configuration, remember to restart the Apache server to apply your changes. This can be done using the command:
```
systemctl restart apache2
```