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

DirectiveDescriptionExample
ServerRootRoot directory of the Apache server installationServerRoot /etc/httpd
ListenSpecify the IP address and port to listen onListen 80
ServerNameSet the server’s fully-qualified domain nameServerName www.example.com
ServerAdminEmail address of the server administratorServerAdmin admin@example.com

Virtual Hosts

DirectiveDescriptionExample
<VirtualHost>Define a virtual host<VirtualHost *:80>
DocumentRootSpecify the document root directoryDocumentRoot /var/www/html
ServerAliasDefine additional server names for a virtual hostServerAlias example.com
ErrorLogSet the path to the error log fileErrorLog /var/log/httpd/error_log
CustomLogDefine a log format and specify log fileCustomLog /var/log/httpd/access_log common

Directory Configuration

DirectiveDescriptionExample
<Directory>Apply configuration to a specific directory<Directory /var/www/html>
OptionsSet various options for a directoryOptions Indexes FollowSymLinks
AllowOverrideAllow .htaccess files to override configurationAllowOverride All
OrderSpecify the order in which allow/deny directives are processedOrder Deny,Allow
DenyDeny access based on host or network addressDeny from 192.168.1.2
AllowAllow access based on host or network addressAllow from all

Logging

DirectiveDescriptionExample
ErrorLogSet the path to the error log fileErrorLog /var/log/httpd/error_log
CustomLogDefine a log format and specify log fileCustomLog /var/log/httpd/access_log common

Modules

DirectiveDescriptionExample
LoadModuleLoad an Apache moduleLoadModule deflate_module modules/mod_deflate.so
LoadModuleLoad SSL/TLS module for secure connectionsLoadModule ssl_module modules/mod_ssl.so

Security

DirectiveDescriptionExample
<Files>Apply configuration to specific files<Files "file.txt">
OrderSpecify the order in which allow/deny directives are processedOrder Deny,Allow
DenyDeny access based on host or network addressDeny from 192.168.1.2
AllowAllow access based on host or network addressAllow from all
RequireSpecify access control based on authentication and authorizationRequire all granted

SSL/TLS Configuration

DirectiveDescriptionExample
SSLEngineEnable SSL/TLS for a virtual hostSSLEngine on
SSLCertificateFilePath to the SSL certificate fileSSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFilePath to the SSL private key fileSSLCertificateKeyFile /etc/ssl/private/server.key
SSLCACertificateFilePath to the SSL CA certificate fileSSLCACertificateFile /etc/ssl/certs/ca.crt

Performance

DirectiveDescriptionExample
KeepAliveEnable or disable persistent connectionsKeepAlive On
MaxKeepAliveRequestsMaximum number of requests allowed during a persistent connectionMaxKeepAliveRequests 100
KeepAliveTimeoutTime (in seconds) the server will wait for a subsequent requestKeepAliveTimeout 5
HostnameLookupsEnable or disable DNS lookups for IP addresses in the logsHostnameLookups Off