Apache HTTP Server Cheat Sheet
Essential Apache HTTPD configuration directives for virtual hosts, modules, rewrites, and reverse proxying.
2 PagesIntermediateFeb 12, 2026
Virtual Host
Serve a domain with a dedicated document root.
apache
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com <Directory /var/www/example.com> AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/example-error.log CustomLog ${APACHE_LOG_DIR}/example-access.log combined</VirtualHost>
Reverse Proxy
Proxy requests to a backend app using mod_proxy.
apache
<VirtualHost *:80> ServerName api.example.com ProxyPreserveHost On ProxyPass / http://127.0.0.1:3000/ ProxyPassReverse / http://127.0.0.1:3000/</VirtualHost># Requires: a2enmod proxy proxy_http
URL Rewriting
Redirect and rewrite URLs with mod_rewrite.
apache
<IfModule mod_rewrite.c> RewriteEngine On # Force HTTPS RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Route non-file requests to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]</IfModule>
CLI & Module Management
Debian/Ubuntu-style module and site management tools.
- a2enmod / a2dismod- Enable/disable an Apache module (e.g. a2enmod ssl)
- a2ensite / a2dissite- Enable/disable a virtual host config in sites-available
- apachectl configtest- Validate configuration syntax before reloading (same as apache2ctl -t)
- systemctl reload apache2- Graceful reload picking up config changes without dropping connections
- mod_ssl- Provides TLS termination via SSLCertificateFile/SSLCertificateKeyFile directives
- mod_headers- Adds/modifies HTTP response headers (e.g. security headers)
Pro Tip
Run 'apachectl configtest' before every reload, and prefer 'AllowOverride None' with directives moved into the vhost config instead of .htaccess for better performance, since Apache re-reads .htaccess on every request.
Was this cheat sheet helpful?
Explore Topics
#ApacheHTTPServer#ApacheHTTPServerCheatSheet#DevOps#Intermediate#VirtualHost#ReverseProxy#URLRewriting#CLIModuleManagement#Networking#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance