keepcalculator

06 Numbers and Powers

Best Apache Modules for Security & Performance

Card No. 06·65235 · Updated · Standard formula, shown below

The best Apache modules to enable for security and performance are mod_http2 for performance and mod_security for security. mod_http2 dramatically improves page load times by multiplexing requests over a single connection, while mod_security provides a web application firewall that blocks common attacks. Together they give you the most significant impact with minimal configuration.

What to Look For

When evaluating Apache modules, focus on these criteria:

  • Security impact – Does it block real attack vectors (SQLi, XSS, DDoS) or just add noise?
  • Performance overhead – Every module costs CPU and memory. The best ones give you more speed or protection than they consume.
  • Ease of configuration – Modules that require deep tuning are often misconfigured, leaving you worse off. Look for sensible defaults.
  • Compatibility – Works with your Apache version (2.4.x is standard) and your existing stack (PHP-FPM, reverse proxy, SSL).
  • Maintenance burden – Does it need frequent rule updates? Is it actively maintained by the Apache project or a large community?

mod_http2

Strengths: Enables HTTP/2, which multiplexes requests over a single TCP connection, eliminates head-of-line blocking, and reduces latency. For sites with many assets (CSS, JS, images), this can cut load times by 20-50%. It also supports server push, though that’s less critical now. It’s built into Apache 2.4.17+ and can be enabled with a single line.

Trade-offs: Requires SSL/TLS (most browsers only use HTTP/2 over HTTPS). It can increase CPU usage slightly due to compression and multiplexing. Some older modules (like mod_autoindex) don’t fully support HTTP/2 features.

Best for: Any site that serves many small assets, especially WordPress, e-commerce, or media-heavy sites. If you’re not using HTTP/2 yet, this is the first performance module to enable.

mod_security

Strengths: A full-featured web application firewall (WAF) that inspects every request and blocks SQL injection, cross-site scripting, and other OWASP Top 10 attacks. It uses a rule set (like OWASP CRS) that’s regularly updated. It also provides virtual patching, letting you block known vulnerabilities before you update your app.

Trade-offs: Can be resource-intensive, especially with complex rules. It requires tuning to avoid false positives (blocking legitimate requests). The OWASP CRS is free, but commercial rule sets cost money. Misconfiguration can break your site, so test in staging first.

Best for: Public-facing web apps that handle sensitive data, or any site that can’t afford a dedicated WAF appliance. It’s a must for e-commerce, banking, or healthcare sites.

mod_deflate

Strengths: Compresses responses with gzip or brotli, reducing bandwidth usage by 60-80% for text-based content (HTML, CSS, JS, JSON). This directly improves load times, especially for mobile users. It’s easy to configure with a few lines.

Trade-offs: Uses CPU to compress, but for most sites the gain outweighs the cost. It doesn’t compress images or videos (those are already compressed). You need to set the right MIME types to avoid compressing already-compressed formats.

Best for: Every site. There’s no reason not to enable mod_deflate for text responses. It’s a low-hanging fruit for performance.

mod_evasive

Strengths: Protects against brute-force attacks and simple DDoS by temporarily blocking IPs that make too many requests in a short time. It’s lightweight and easy to configure (max requests per second, blacklist duration). It can also block requests from IPs that trigger too many 404s.

Trade-offs: Not a full DDoS solution – it only works at the application level and can be bypassed by distributed attacks. It can block legitimate users if you set thresholds too low. It’s not included in Apache by default; you need to install it separately.

Best for: Small to medium sites that want a simple layer of protection against brute-force login attempts or scraper bots. It’s a good complement to mod_security.

mod_headers

Strengths: Allows you to set security-related HTTP headers like Content-Security-Policy, X-Frame-Options, and Strict-Transport-Security. These headers prevent clickjacking, XSS, and protocol downgrade attacks. It also lets you set caching headers (Cache-Control, Expires) to improve performance. It’s built into Apache and incredibly flexible.

Trade-offs: It’s not a magic bullet – you need to know which headers to set and what values are appropriate for your site. Setting a strict CSP can break inline scripts if you’re not careful. It only affects response headers, not request headers.

Best for: Any site that wants to harden its security posture without adding a heavy module. It’s especially useful for sites that handle user authentication.

mod_ssl (with modern configuration)

Strengths: Enables HTTPS, which is non-negotiable for security and performance (HTTP/2 requires it). It also allows you to configure TLS settings like protocol versions and cipher suites. Using a modern configuration (TLS 1.2+, strong ciphers) protects against eavesdropping and man-in-the-middle attacks. It also enables OCSP stapling, which speeds up certificate validation.

Trade-offs: SSL/TLS handshake adds latency, but with session resumption and HTTP/2, that’s minimal. It requires a certificate (free via Let’s Encrypt). Misconfiguration can weaken security, so use a tool like SSL Labs to test.

Best for: Every site. There’s no reason to run plain HTTP anymore. Even if you don’t have sensitive data, HTTPS is a ranking signal and a trust signal.

How to Choose

Your choice depends on your budget, use case, and risk tolerance.

  • Budget: All modules listed are free and open-source. The cost is in time – mod_security and mod_headers require more configuration and testing. If you have limited admin time, start with mod_deflate, mod_headers, and mod_ssl, which are low-effort. Add mod_security later if you need deeper protection.
  • Use case: For a simple blog, mod_http2 and mod_deflate are enough. For an e-commerce site, add mod_security and mod_evasive. For a high-traffic site, focus on mod_http2 and mod_deflate, and consider a reverse proxy like Varnish for caching.
  • Trade-offs: Security modules can hurt performance if misconfigured. mod_security’s rule evaluation adds latency; mod_evasive can block real users. Performance modules like mod_http2 can increase CPU usage. Always test in a staging environment and monitor your server metrics after enabling any module.

Frequently Asked Questions

Q: Can I enable all these modules at once?
A: Yes, but be careful. mod_security and mod_evasive together can be aggressive. Start with mod_http2, mod_deflate, mod_headers, and mod_ssl. Add mod_security and mod_evasive gradually, testing each.

Q: Do I need mod_security if I have a cloud WAF?
A: No, but it’s a good defense-in-depth layer. If you already have a WAF from Cloudflare or AWS, mod_security may be redundant. However, it can catch attacks that bypass the cloud WAF.

Q: Will mod_http2 work with my old Apache version?
A: mod_http2 is available in Apache 2.4.17 and later. If you’re on 2.2 or older, you need to upgrade. Most modern distros have 2.4.x.

Q: How do I know if mod_deflate is working?
A: Use your browser’s developer tools (Network tab) and check the response headers for Content-Encoding: gzip. You can also use online tools to test compression.

Q: Can mod_evasive block me from my own site?
A: Yes, if you set thresholds too low. For example, if you set max requests per second to 5 and you refresh a page 10 times quickly, you’ll get blocked. Start with higher thresholds and adjust based on your traffic.

Q: Is mod_ssl really a performance module?
A: It can improve performance if you enable session resumption and OCSP stapling, which reduce handshake latency. But its primary benefit is security. It’s essential for HTTP/2, so it indirectly boosts performance.

Bottom Line

Start with the four that give you the most for your effort: mod_http2, mod_deflate, mod_headers, and mod_ssl. These are easy to configure, have minimal downsides, and provide a solid security and performance baseline. Then, if you need deeper security, add mod_security with the OWASP Core Rule Set. Finally, consider mod_evasive if you face brute-force or scraping attacks. Remember to test every change in a staging environment and monitor your server’s performance and error logs.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →