We Are Always Excited To Take On New Projects!
https://www.cybercafestore.com
330 Queen St, Ottawa, ON K1R 7Y5, Canada
An in-depth guide to installing, tuning, and securing Apache on Linux, covering modules, virtual hosts, SSL, headers, caching, load balancing, monitoring, and maintenance.
Note:
If you’re using a managed web hosting panel such as CloudPanel, cPanel, or Plesk, Apache is already installed and configured for you. Skip to the Performance Tuning and Security Hardening sections below.
Apache remains one of the most widely used web servers thanks to its flexibility, module ecosystem, and proven stability. When configured correctly it can serve static and dynamic content efficiently, host multiple sites, and defend against common threats. This guide walks you through each step—from fresh installation to advanced performance tuning and security hardening—so your Apache server runs at top speed and stays protected.
Before you begin, ensure you have:
Update your package list
sudo apt update
Install Apache
sudo apt install apache2
Verify the installation
apache2 -v
Enable and start the service
sudo systemctl enable apache2
sudo systemctl start apache2
Keeping Apache up to date ensures you have the latest security patches and feature improvements.
Apache organizes configuration into:
To enable a new site:
sudo a2ensite yourdomain.com.conf
sudo systemctl reload apache2
Always check syntax before reloading:
sudo apachectl configtest
Apache offers multiple Multi-Processing Modules, select based on workload:
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo systemctl restart apache2
Adjust persistent connections and timeouts in apache2.conf
:
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2
Timeout 60
Reduce transfer sizes for text-based assets:
sudo a2enmod deflate
Add to /etc/apache2/conf-available/deflate.conf
:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/javascript application/json
</IfModule>
sudo systemctl reload apache2
Enable modules:
sudo a2enmod expires headers
Configure caching in your virtual host:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 30 days"
ExpiresByType application/javascript "access plus 30 days"
ExpiresByType image/jpeg "access plus 30 days"
</IfModule>
<IfModule mod_headers.c>
Header set Cache-Control "public"
</IfModule>
Install Certbot and the Apache plugin
sudo apt install certbot python3-certbot-apache
Obtain and install a certificate
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
Enable auto-renewal
sudo systemctl enable certbot.timer
Using HTTPS improves user trust, SEO rankings and protects data in transit.
Add these directives inside your <VirtualHost *:443>
block:
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "no-referrer-when-downgrade"
Header always set Content-Security-Policy "default-src 'self';"
Install and configure to block malicious requests:
sudo apt install libapache2-mod-security2 libapache2-mod-evasive
sudo a2enmod security2 evasive
Basic mod_evasive config in /etc/apache2/mods-available/evasive.conf
:
<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 5
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
</IfModule>
Review loaded modules and disable anything unnecessary:
apache2ctl -M
sudo a2dismod status userdir autoindex
sudo systemctl restart apache2
Host multiple sites or distribute traffic across backends:
Example VirtualHost
Simple Load Balancer using mod_proxy
Enable modules:
sudo a2enmod proxy proxy_balancer proxy_http lbmethod_byrequests
Configure in your site file:
<Proxy "balancer://mycluster">
BalancerMember http://10.0.0.10:8080
BalancerMember http://10.0.0.11:8080
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass "/" "balancer://mycluster/"
ProxyPassReverse "/" "balancer://mycluster/"
Access Logs in combined format
CustomLog /var/log/apache2/access.log combined
Error Logs with warning level
ErrorLog /var/log/apache2/error.log
LogLevel warn
/etc/apache2/
nightly to remote storageRegularly:
Following these steps ensures your Apache server delivers content quickly, stays protected against web threats, and scales as your traffic grows. Consistent maintenance, monitoring and incremental tuning keep your environment performant and secure.
Call to Action:
Need expert help configuring Apache, optimizing performance or securing your web infrastructure? Contact Hunter Tech for a personalized consultation and hands-on support.
Your email address will not be published. Required fields are marked *