To configure the mod\_headers module in Apache, you need to follow the steps below.
1. The mod\_headers module must be enabled on your Apache server. To do so, use the following command:
```
sudo a2enmod headers
```
1. After successfully enabling the mod\_headers module, you can start configuring it in the Apache configuration file. If you want to add a specific header to HTTP responses, you can use the ‘Header’ directive in your configuration.
The main syntax of this directive is as follows:
```
Header set|append|add|unset header value [expr=expression]
```
- set: This will set a header and replaces any header that has same name.
- append: This will add a header.
- add: Similar to append but it does not create a comma-separated list.
- unset: This will remove a header.
For example, if you want to set a “X-Content-Type-Options” header in your HTTP responses, you can use the following directive:
```
Header always set X-Content-Type-Options: “nosniff“
```
Make sure to put this line either in the main server configuration file (httpd.conf), inside a
1. To configure this module in a VirtualHost, you’ll need to use the
```
```
1. Don’t forget to save your changes and restart your Apache server to ensure the changes take effect.
```
systemctl restart apache2
```
or
```
service apache2 restart
```
That’s it. With these steps, you have successfully configured the mod\_headers module in Apache. Now, the required HTTP headers will be added to every HTTP response served by your Apache server.