Apache Httpd Cheat Sheet On this page 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 [email protected]
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
LogLevel
Set the verbosity level of the error log LogLevel warn
LogFormat
Define a custom log format LogFormat "%h %l %u %t \"%r\" %>s %b" 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
LoadModule
Load rewrite module for URL rewriting LoadModule rewrite_module modules/mod_rewrite.so
Security# Directive Description Example <Files>
Apply configuration to specific files <Files ".htaccess">
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
ServerTokens
Control server version information sent to clients ServerTokens Prod
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
SSLProtocol
Specify supported SSL/TLS protocol versions SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite
Define the cipher suite to be negotiated SSLCipherSuite HIGH:!aNULL:!MD5
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
Timeout
Time (in seconds) before receiving and sending timeout Timeout 300
MaxRequestWorkers
Maximum number of connections that will be processed simultaneously MaxRequestWorkers 400