Apache HTTP Server
Complete guide to Apache web server configuration, virtual hosts, .htaccess, modules, and performance tuning
8 min read
apachehttpdweb-serverhtaccessvirtual-hostsmodulesrewritessl
Table of Contents
Installation & Basic Commands
Installing and managing Apache
Installation
Installing Apache on different platforms
bash
🌐 Most widely used web server
📦 Available as apache2 or httpd package
🔧 Highly modular and extensible
⚡ Config at /etc/apache2/ or /etc/httpd/
Basic Commands
Essential Apache management commands
bash
✅ Always test config with configtest before reload
🔄 Graceful restart maintains active connections
📁 Config structure varies by distribution
📊 Logs in /var/log/apache2/ or /var/log/httpd/
Virtual Hosts
Configuring virtual hosts for multiple sites
Basic Virtual Host
Setting up a basic virtual host
apache
🌐 Virtual hosts allow multiple sites on one server
📝 Each vhost needs unique ServerName
🔗 Enable with a2ensite command
⚡ Name-based is most common type
SSL/TLS Configuration
Configuring HTTPS with SSL certificates
apache
🔒 Always use HTTPS in production
📜 Let's Encrypt for free SSL certificates
⚡ Enable HTTP/2 for better performance
🔐 HSTS header enforces HTTPS
.htaccess & URL Rewriting
Directory-level configuration and URL rewriting
.htaccess Basics
Common .htaccess configurations
apache
📁 .htaccess provides directory-level config
🔒 Requires AllowOverride All in vhost
⚡ Can impact performance if overused
🎯 Great for shared hosting environments
URL Rewriting
Advanced URL rewriting with mod_rewrite
apache
🔄 mod_rewrite is powerful but complex
📝 Test rules carefully with RewriteLog
🎯 Order matters - most specific first
⚡ Use RewriteCond for conditional rules
Modules & Performance
Apache modules and performance optimization
Essential Modules
Common Apache modules and their usage
bash
🔧 Apache has 100+ available modules
📦 Enable only needed modules for performance
⚡ mod_deflate saves bandwidth
🔒 mod_security adds WAF capabilities
Performance Tuning
Optimizing Apache for better performance
apache
⚙️ Choose appropriate MPM for workload
🗜️ Enable compression for text content
💾 Use caching for static content
📊 Monitor with mod_status
Security & Access Control
Securing your Apache server
Security Best Practices
Essential security configurations
apache
🔒 Hide version info and disable directory listing
🛡️ Use security headers to prevent attacks
⚠️ Implement ModSecurity for WAF protection
🔐 Use fail2ban to block attackers