The main Apache configuration directives
The complete Apache directives list.
Listen
This directive sets the ip(s) and port on which the Apache server listens for connection.
Listen: 192.168.0.1:80
Instead of 192.168.0.1 the actual IP must be used. Port 80 is the regular http port and 443 is the default https port. If the server has multiple interfaces (phisical or virtual) the * character must be used to cover all IPs.
Listen *:80
User / Group
These directives set the user and the group under which the http server will be running.
ServerName
This sets the name of the server reported by Apache.
ServerRoot
This sets the locations of the server and all its files. All paths from httpd.conf will be relative to this path.
DocumentRoot
This is the WebSpace. This is the location where Apache will search for the files and folders requested by the clients.
DirectoryIndex
This sets the default file served by Apache if the client has not requested a specific file. For this to work the dir_module must be loaded.
LoadModule dir_module modules/mod_dir.so
<IfModule dir_module>
DirectoryIndex index.php index.htm index.html
</IfModule>
IndexOptions
This generates a folder’s index if there’s no file matching the options in DirectoryIndex. It needs the autoindex_module.
LoadModule autoindex_module modules/mod_autoindex.so
IndexOptions FancyIndexing FoldersFirst
IndexIgnore
It needs the autoindex module (mod_autoindex.so).
IndexIgnore *.jpeg
Alias
This is used to map an URL or local directory to a location outside the document tree. It requires the mod_alias.so module.
LoadModule alias_module mod_alias.so
Alias /var /path_outsite_document_tree
There is a variant to this called ScriptAlias used for folders with CGI scripts.
Redirect
This is similar to Alias but it’s used to map a resource from local Webspace to a remote one.
Redirect /dir http://www.site.com
ErrorLog
This sets the logging options. Some possible values for LogLevel: debug, info, notice, warn, error, crit, alert, emerg.
ErrorLog /log_path
LogLevel warn
ErrorDocument
This sets specific answers of the server in case of an specific errors (either as a message or as path to a file).
ErrorDocument 500 “Error message”
ErrorDocument 404 /error.html
Incomplete list of error numbers:
400 Bad Request – HTTP_BAD_REQUEST
401 Authorization Required – HTTP_UNAUTHORIZED
402 Payment Required – HTTP_PAYMENT_REQUIRED
403 Forbidden – HTTP_FORBIDDEN
404 Not Found – HTTP_NOT_FOUND
405 Method Not Allowed – HTTP_METHOD_NOT_ALLOWED
406 Not Acceptable – HTTP_NOT_ACCEPTABLE
407 Proxy Authentication Required – HTTP_PROXY_AUTHENTICATION_REQUIRED
408 Request Time-out – HTTP_REQUEST_TIME_OUT
409 Conflict – HTTP_CONFLICT
410 Gone – HTTP_GONE
411 Length Required – HTTP_LENGTH_REQUIRED
413 Request Entity Too Large – HTTP_REQUEST_ENTITY_TOO_LARGE
414 Request-URI Too Large – HTTP_REQUEST_URI_TOO_LARGE
500 Internal Server Error – HTTP_INTERNAL_SERVER_ERROR
501 Method Not Implemented – HTTP_NOT_IMPLEMENTED
503 Service Temporarily Unavailable – HTTP_SERVICE_UNAVAILABLE
505 HTTP Version Not Supported – HTTP_VERSION_NOT_SUPPORTED
<Directory>
This is used to set some options for a specific directory from the Webspace and it can only be used as a core setting (not in .htaccess).
<Directory /path>
Options Indexes FollowSymLinks # example 1
AllowOverride ALL # example 2
</Directory>
If AllowOverride is set on None, Apache does not even read .htaccess.
<FilesMatch>
This directive is used to restrict access to certain files. This can be used in .htaccess and regular expressions can be used.
<FilesMatch “^\.ht”>
Order allow,deny
Deny from all
</FilesMatch>
<Files>
This is equivalent to FilesMatch but the regular expression must be preceded by ~
<Files ~ “\.(gif|jp?g|png)$”>
Order allow,deny
Allow from 192.168.0.1
</Files>
mime.types
Associate a server action with the file type requested by the client. This required mod_mime.so.
LoadModule mime_module /modules/mod_mime.so
DefaultType text/plain
TypesConfig conf/mime.types