Dino Geek, try to help you

How to configure mod_headers module in Apache?


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 tag or in a .htaccess file.

1. To configure this module in a VirtualHost, you’ll need to use the tag in your Apache configuration file. Here’s an example configuration:

```
ServerName www.example.com DocumentRoot /var/www/html Options Indexes FollowSymLinks AllowOverride None Require all granted Header set X-Content-Type-Options: “nosniff“ Header set X-XSS-Protection: “1; mode=block”

```

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.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use