Optimize Apache HTTP server performance with caching, compression and worker tuning

Intermediate 35 min Apr 03, 2026 1,183 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Boost Apache performance through worker MPM optimization, compression modules, and intelligent caching strategies. Achieve 3-5x performance improvements for high-traffic production workloads.

Prerequisites

  • Root or sudo access
  • 4GB+ RAM recommended for high-performance settings
  • Basic knowledge of Apache configuration

What this solves

Apache HTTP server performance can bottleneck under high traffic loads due to inefficient worker configurations, missing compression, and lack of caching. This tutorial optimizes Apache through worker MPM tuning for concurrent connections, enables mod_deflate and Brotli compression to reduce bandwidth usage, and implements browser and proxy caching with mod_cache. These optimizations typically improve response times by 60-80% and increase concurrent user capacity by 3-5x.

Step-by-step configuration

Update system packages and install Apache

Start with a fresh Apache installation and enable essential performance modules.

sudo apt update && sudo apt upgrade -y
sudo apt install -y apache2 apache2-utils brotli
sudo systemctl enable apache2
sudo dnf update -y
sudo dnf install -y httpd httpd-tools brotli
sudo systemctl enable httpd

Enable performance and compression modules

Enable Apache modules required for performance optimization including worker MPM, compression, caching, and monitoring.

sudo a2dismod mpm_prefork
sudo a2enmod mpm_worker
sudo a2enmod deflate
sudo a2enmod expires
sudo a2enmod headers
sudo a2enmod cache
sudo a2enmod cache_disk
sudo a2enmod status
sudo a2enmod info
sudo a2enmod rewrite
# Modules are compiled in by default on RHEL-based systems
# Create module loading configuration
sudo tee /etc/httpd/conf.modules.d/00-performance.conf > /dev/null << 'EOF'
LoadModule mpm_worker_module modules/mod_mpm_worker.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule expires_module modules/mod_expires.so
LoadModule headers_module modules/mod_headers.so
LoadModule cache_module modules/mod_cache.so
LoadModule cache_disk_module modules/mod_cache_disk.so
LoadModule status_module modules/mod_status.so
LoadModule info_module modules/mod_info.so
LoadModule rewrite_module modules/mod_rewrite.so
EOF

Configure worker MPM for high concurrency

Optimize worker process and thread settings based on your server resources. These settings handle 4GB+ RAM servers with high concurrent loads.

Configure compression with mod_deflate

Enable gzip compression for text-based content to reduce bandwidth usage by 60-80%. This configuration targets common web content types.

Configure Brotli compression

Enable Brotli compression for better compression ratios than gzip, especially for text content. Brotli provides 15-25% better compression.

sudo apt install -y libapache2-mod-brotli
sudo a2enmod brotli
# Install mod_brotli from EPEL
sudo dnf install -y epel-release
sudo dnf install -y httpd-mod-brotli

Configure disk-based caching with mod_cache

Enable intelligent caching to serve frequently requested content from disk cache, reducing server load and improving response times.

# Create cache directory with proper permissions
sudo mkdir -p /var/cache/apache2/mod_cache_disk
sudo chown www-data:www-data /var/cache/apache2/mod_cache_disk
sudo chmod 755 /var/cache/apache2/mod_cache_disk
sudo mkdir -p /var/cache/httpd/mod_cache_disk
sudo chown apache:apache /var/cache/httpd/mod_cache_disk
sudo chmod 755 /var/cache/httpd/mod_cache_disk

Configure browser caching with expires headers

Set appropriate expiration headers to enable browser caching and reduce repeat requests for static assets.

Configure performance monitoring with mod_status

Enable server status and info pages for performance monitoring. Restrict access to localhost for security.

Apply security hardening for performance modules

Secure the performance configuration by hiding server information and preventing information disclosure.

# Hide Apache version and OS information
ServerTokens Prod
ServerSignature Off

# Prevent access to .htaccess files


# Prevent access to cache directories


# Security headers for performance-related content


# Limit request size to prevent DoS
LimitRequestBody 10485760
LimitRequestFields 100
LimitRequestFieldSize 1024
LimitRequestLine 4094
sudo a2enconf security-performance
# Hide Apache version and OS information
ServerTokens Prod
ServerSignature Off

# Prevent access to .htaccess files


# Prevent access to cache directories


# Security headers for performance-related content


# Limit request size to prevent DoS
LimitRequestBody 10485760
LimitRequestFields 100
LimitRequestFieldSize 1024
LimitRequestLine 4094

Configure firewall access

Ensure Apache can accept HTTP and HTTPS connections through the system firewall.

sudo ufw allow 'Apache Full'
sudo ufw reload
sudo ufw status
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-services

Start and enable Apache service

Start Apache with the new performance configuration and enable automatic startup.

Automated install script

Run this to automate the entire setup

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. Fully managed, with one fixed contact who knows your setup.

You get one fixed contact who knows your setup

Rotterdam 01:26 · reachable in a message, no ticket form