Apache Httpd Cheat Sheet
This cheat sheet provides a quick reference guide for configuring the Apache HTTP Server, a widely-used open-source web server. Whether you are a beginner setting up your first server or an experienced administrator fine-tuning performance, this compilation of essential directives and configurations will help you navigate through the intricacies of Apache configuration files.
How to Use
The cheat sheet is organized into several sections, covering fundamental aspects of Apache server configuration. Each directive is presented in a tabular format, providing a clear and concise overview of its purpose and usage. Whether you are dealing with basic server settings, virtual hosts, directory configurations, logging, modules, security, SSL/TLS, or performance optimizations, you can easily find the information you need.
Customization
Feel free to customize this cheat sheet to match your specific requirements. Apache configurations can vary based on your server environment, and adapting these directives ensures that your Apache server aligns with your project’s needs. The examples provided serve as a starting point, offering practical insights into common scenarios.
Whether you’re a developer, system administrator, or someone exploring web server configurations, use this cheat sheet as a handy reference to streamline your Apache HTTP Server setup and maintenance tasks.
Happy configuring!
Basic Configuration
Directive | Description | Example |
---|
ServerRoot | Root directory of the Apache server installation | ServerRoot /etc/httpd |
Listen | Specify the IP address and port to listen on | Listen 80 |
ServerName | Set the server’s fully-qualified domain name | ServerName www.example.com |
ServerAdmin | Email address of the server administrator | ServerAdmin admin@example.com |
Virtual Hosts
Directive | Description | Example |
---|
<VirtualHost> | Define a virtual host | <VirtualHost *:80> |
DocumentRoot | Specify the document root directory | DocumentRoot /var/www/html |
ServerAlias | Define additional server names for a virtual host | ServerAlias example.com |
ErrorLog | Set the path to the error log file | ErrorLog /var/log/httpd/error_log |
CustomLog | Define a log format and specify log file | CustomLog /var/log/httpd/access_log common |
Directory Configuration
Directive | Description | Example |
---|
<Directory> | Apply configuration to a specific directory | <Directory /var/www/html> |
Options | Set various options for a directory | Options Indexes FollowSymLinks |
AllowOverride | Allow .htaccess files to override configuration | AllowOverride All |
Order | Specify the order in which allow/deny directives are processed | Order Deny,Allow |
Deny | Deny access based on host or network address | Deny from 192.168.1.2 |
Allow | Allow access based on host or network address | Allow from all |
Logging
Directive | Description | Example |
---|
ErrorLog | Set the path to the error log file | ErrorLog /var/log/httpd/error_log |
CustomLog | Define a log format and specify log file | CustomLog /var/log/httpd/access_log common |
Modules
Directive | Description | Example |
---|
LoadModule | Load an Apache module | LoadModule deflate_module modules/mod_deflate.so |
LoadModule | Load SSL/TLS module for secure connections | LoadModule ssl_module modules/mod_ssl.so |
Security
Directive | Description | Example |
---|
<Files> | Apply configuration to specific files | <Files "file.txt"> |
Order | Specify the order in which allow/deny directives are processed | Order Deny,Allow |
Deny | Deny access based on host or network address | Deny from 192.168.1.2 |
Allow | Allow access based on host or network address | Allow from all |
Require | Specify access control based on authentication and authorization | Require all granted |
SSL/TLS Configuration
Directive | Description | Example |
---|
SSLEngine | Enable SSL/TLS for a virtual host | SSLEngine on |
SSLCertificateFile | Path to the SSL certificate file | SSLCertificateFile /etc/ssl/certs/server.crt |
SSLCertificateKeyFile | Path to the SSL private key file | SSLCertificateKeyFile /etc/ssl/private/server.key |
SSLCACertificateFile | Path to the SSL CA certificate file | SSLCACertificateFile /etc/ssl/certs/ca.crt |
Directive | Description | Example |
---|
KeepAlive | Enable or disable persistent connections | KeepAlive On |
MaxKeepAliveRequests | Maximum number of requests allowed during a persistent connection | MaxKeepAliveRequests 100 |
KeepAliveTimeout | Time (in seconds) the server will wait for a subsequent request | KeepAliveTimeout 5 |
HostnameLookups | Enable or disable DNS lookups for IP addresses in the logs | HostnameLookups Off |