Apache is one of the most popular web servers used to host websites and web applications. More than half of the websites on the Internet are served by Apache, and this server is great for both larger and smaller projects.
The Apache web server is very flexible and customizable. Many functions are not included in the kernel, but are implemented in the form of modules. Apache modules help to optimize the performance of the web server, make it more secure, control additional features and get more detailed information about requests. In this article, we will look at how to view the list of modules, what they are, how to configure them, and also present the main and most useful Apache modules.
What is an Apache module?
The Apache module allows you to extend the functionality of the web server, we already know this. All modules are made as dynamically linked libraries with *.so extension. They are located in a separate folder for modules and can be installed either manually or using the distribution’s package manager.
Also, in order to activate a module, it must be enabled in the program configuration; usually, specific settings for the module are also specified there. Next, we will look at this in more detail.
How to enable Apache?
As I said, installing apache modules can be done in many ways, for example using a package manager or even compiling manually. But in order to load them, Apache needs to know where the dynamic library is located and the basic settings in order to load the module correctly.
Usually in the Apache configuration folder, for example, /etc/apache/mods-available there is a module file in which its library is imported and settings are specified. Thus, to enable the module, it will be enough to transfer the file with its configuration to the folder from which the configuration is loaded when Apache starts. For example, in /etc/apache2/mods-enabled. First, let’s see the list of apache modules:
sudo apachectl -M
So you can look at apache modules in Ubuntu and distributions based on it, in other systems the location of files and commands may differ, but the essence is the same, the address of the module library must be included in the main configuration, no matter how. Ubuntu also has utilities for automatically copying files to where you need them when you activate a module, this is a2enmod. For example, enable the rewrite module:
sudo a2enmod rewrite
Or disable: install apache modules
sudo a2dismod rewrite
Now let’s look at the main Apache modules that you may need.
Best Apache Modules
1. PageSpeed
PageSpeed module – allows you to optimize the performance of the web server and speed up the loading of content. It supports data compression, caching, file resizing, and stripping extra spaces and characters from files. The module was developed by Google to increase the speed of loading content. To install the module in Ubuntu, run the following commands:
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
sudo dpkg -i mod-pagespeed-*.deb
sudo apt -f install
sudo systemctl restart apache2
We download the latest version of the module from the official site, then install the package, its dependencies and restart the web server. If the dpkg command throws a dependency resolution error, that’s fine, it will be fixed by calling apt. The module will be automatically activated after installation. You can look at the list of Apache modules again to make sure the module has been activated:
sudo apachectl -M | grep pagespeed
The config file is located at /etc/apache2/mods-available/pagespeed.conf where you can configure various additional settings.
2. Security
The mod_security module adds an extra layer of security by denying certain types of traffic based on rules and filters. This is a software firewall that allows you to protect your web server from some vulnerabilities and problems. You can install this module from the official repositories:
sudo apt install libapache2-modsecurity
Then the module needs to be activated, for example, using a2enmod:
sudo a2enmod mod-security
The configuration file is located in the /etc/apache2/mod-security.conf folder, and is also pointed to by a symbolic link from /etc/modsecurity. Customize the rules depending on your needs and features of the site. Then activate the protection by changing the value of SecRuleEngine from DetectionOnly to On:
Don’t forget to restart the web server for residual module activation.
3. Status
It is one of the most useful and simple modules and is installed by default with Apache. With mod_status you can estimate the load on the server as well as the number of requests. The configuration file is located in the /etc/apache2/mods-available folder:
sudo vi /etc/apache2/mods-available/status.conf
Here, in the Locaction section, you need to add the line Allow from with your IP address, from which the statistics will be accessed:
Then save your changes and restart Apache. Now, to view the statistics, it will be enough to open in the browser:
Here you will find a lot of useful information about server load.
4. Spamhaus
Spamhaus is a module that allows you to block requests from IP addresses that are considered hacker addresses. You can install the spamhaus module from the official repositories with the command:
sudo apt install libapache2-mod-spamhaus
The configuration file is located at /etc/apache2/mods-available/mod_spamhaus.conf. You can filter modules based on various criteria, for example, MS_METHODS allows you to block IP addresses that have been seen in an http flood. You can also set up a white list of IP addresses. After installation, the module must be activated:
sudo a2enmod mod-spamhauspamhaus-drop.git
sudo systemctl restart apache2
5. Rewrite
It is one of the most popular and most used Apache modules and is used by most sites. It allows you to generate easy-to-read URLs for documents, perform redirects, and transform the content of requests in various ways. The module is installed by default, but in some distributions it needs to be activated:
sudo a2enmod rewrite
sudo systemctl restart apache2
All module settings are done through httaccess files, although you can use to specify these settings anywhere.
Findings
In this article, we have covered the main Apache modules that you can use. But this is far from a complete list. New modules are constantly being created that allow you to expand the program’s capabilities and change its standard behavior. But keep in mind that the more code you add to the server, the greater the overhead and the more likely it is that there is a critical bug in the code. Choose only well-tested modules that are used by a large number of users.