Apache HTTP Server is one of the most widely used web servers in the world—powering everything from personal blogs to enterprise-grade applications. But with popularity comes risk: an exposed Apache instance can be a prime target for attackers looking to exploit misconfigurations, outdated modules, or directory leaks.
Whether you’re running a self-hosted site or managing backend infrastructure, this guide will walk you through essential steps to secure your Apache web server—without sacrificing performance or functionality.

Why Apache Security Matters
Apache is often deployed as the front door to your applications and data. An insecure configuration could lead to:
- Information disclosure (like directory listing or server version)
- Unauthorized access
- Remote code execution (RCE)
- Man-in-the-middle attacks
- Website defacement or malware injection
Security is not a set-it-and-forget-it task. It’s a continuous process of patching, hardening, monitoring, and reviewing.
1. Keep Apache Updated
Why: Vulnerabilities are patched frequently in Apache and its modules.
What to do:
- Use your package manager:
sudo apt update && sudo apt upgrade apache2 # Ubuntu/Debian sudo yum update httpd # RHEL/CentOS - Subscribe to Apache Security Advisories
2. Disable Unused Modules
Why: Every enabled module is a potential attack surface.
What to do:
- List active modules:
apachectl -M - Disable what you don’t use (e.g.,
autoindex,status,cgi,userdir)a2dismod autoindex status cgi userdir systemctl restart apache2
3. Turn Off Directory Listing
Why: Prevent users from viewing the file structure if no index file is present.
How:
In your Apache config or .htaccess file:
<Directory /var/www/html>
Options -Indexes
</Directory>
4. Hide Apache Version & OS Info
Why: Revealing your Apache version and OS gives attackers helpful reconnaissance.
How:
Edit apache2.conf or httpd.conf:
ServerSignature Off
ServerTokens Prod
This will remove version info from error pages and HTTP headers.
5. Use HTTPS with a Strong TLS Configuration
Why: HTTPS ensures secure, encrypted connections.
What to do:
- Install Let’s Encrypt for free SSL certificates:
sudo apt install certbot python3-certbot-apache sudo certbot --apache - Use a secure TLS config:
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLCipherSuite HIGH:!aNULL:!MD5 SSLHonorCipherOrder on
6. Enable HTTP Security Headers
Why: Helps prevent clickjacking, XSS, MIME sniffing, and more.
Add these to your Apache config:
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Content-Security-Policy "default-src 'self';"
Use tools like securityheaders.com to check your score.
7. Use ModSecurity (WAF)
Why: It provides a basic Web Application Firewall (WAF) to detect/block malicious HTTP requests.
Install & enable ModSecurity:
sudo apt install libapache2-mod-security2
sudo a2enmod security2
Enable OWASP Core Rule Set (CRS) and tune rules to avoid false positives.
8. Monitor Logs for Intrusions
Why: Detect suspicious activity like brute force, injection attempts, or 404 probing.
Monitor:
/var/log/apache2/access.log/var/log/apache2/error.log
Use tools like:
fail2banfor automated IP blockingGoAccessfor real-time log analytics- SIEM integrations (e.g., ELK stack)
9. Restrict Access to Sensitive Files & Admin Areas
What to restrict:
.git/,.env,config.php, etc./admin,/wp-admin, or other backends
Example:
<FilesMatch "\.(htaccess|env|git|ini|log|bak)$">
Require all denied
</FilesMatch>
Use IP whitelisting for admin access:
<Location "/admin">
Require ip 192.168.1.100
</Location>
10. Regularly Test Your Apache Security
Use free tools:
- SSL Labs Server Test
- Nikto
- Nmap with HTTP scripts
- OpenVAS
Make Apache part of your DevSecOps process—run tests after every config change.
Bonus Tips
- Use firewalls (UFW, iptables) to restrict traffic to only necessary ports (80/443).
- Enable Rate Limiting with
mod_evasiveto block DDoS or brute force. - Use chroot jail or containers to isolate Apache from the OS.
Final Thoughts
Apache is powerful—but power without control invites risk. By hardening your configuration, applying the principle of least privilege, and monitoring proactively, you can turn Apache from a soft target into a hardened asset.
Remember: The default config is not secure. Take the time to secure it properly—it’s always worth it.
Want a checklist for securing Apache? Subscribe to SecureBytesBlog and get our “Web Server Hardening Starter Pack” sent straight to your inbox.


