Skip to main content

Configuring Core Server Directives

1. Setting ServerName Directive

Directive Values Description
ServerName example.com or 192.168.1.1:80 Defines the server's fully qualified domain name or IP address with port.

Example: Setting ServerName in httpd.conf

ServerName example.com:80
Note: It is highly recommended to set ServerName explicitly to avoid potential issues with virtual hosts and server identification.

2. Configuring ServerAdmin Email

Directive Values Description
ServerAdmin admin@example.com Email address of the server administrator. Used in error messages and server status pages.

Example: Setting ServerAdmin Email

<VirtualHost *:80>
    ServerName example.com
    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/html
</VirtualHost>
Note: The ServerAdmin directive is required for proper server operation and should always be set to a valid email address.

3. Setting DocumentRoot Directory

Directive Values Description
DocumentRoot /var/www/html Sets the directory from which documents are served

Example: Setting DocumentRoot

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/example.com
</VirtualHost>
Note: The directory specified must exist and have appropriate permissions for the Apache user to read files.

4. Configuring Listen Directives

Directive Values Description
Listen 80, 443, 192.168.1.1:8080 Specifies the address and port to which the server listens for requests
ListenBackLog 511 Maximum length of the queue of pending connections
ListenOptions deferred_accept, reuseport Additional options for the listen socket

Example: Basic Listen Configuration

<VirtualHost *:80>
    Listen 80
    ServerName example.com
</VirtualHost>

Example: Listen on Specific IP and Port

<IfModule mod_ssl.c>
    Listen 192.168.1.10:443
    SSLCertificateFile /path/to/cert.pem
    SSLCertificateKeyFile /path/to/key.pem
</IfModule>
Note: Multiple Listen directives can be used to bind to different addresses or ports.
Warning: Binding to 0.0.0.0 makes the server accessible from any IP address.

5. Setting ServerRoot Path

Directive Values Description
ServerRoot /etc/httpd Path to the directory containing the server's configuration files and logs

Example: Setting ServerRoot

<IfModule !mod_http2.c>
    LoadModule http2_module modules/mod_http2.so
</IfModule>

ServerRoot "/etc/httpd"
Note: The ServerRoot must be an absolute path and should not contain symbolic links.

6. Configuring User and Group

Directive Description Default Notes
User Sets the user ID under which the server runs daemon (Unix) or Apache (Windows) Must be a valid system user
Group Sets the group ID under which the server runs daemon (Unix) or Apache (Windows) Must be a valid system group

Example: Setting User and Group

<IfModule !mod_unixd.c>
    User www-data
    Group www-data
</IfModule>
Note: On Unix-like systems, the User and Group directives are only available if the mod_unixd module is loaded. On Windows, these directives are not supported.
Warning: Changing the user and group can affect server permissions and security. Ensure that the specified user has appropriate access to server files and directories.

7. Setting Timeout Values

Directive Default Description
Timeout 60 Maximum time in seconds to wait for data from a client or server before closing the connection
KeepAliveTimeout 5 Time in seconds to wait for a subsequent request when KeepAlive is enabled
RequestTimeout 60 Maximum time in seconds to wait for a complete request before closing the connection

Example: Setting Timeout Values

<IfModule mod_timeout.c>
    Timeout 120
    KeepAliveTimeout 10
    RequestTimeout 90
</IfModule>

8. Configuring Keep-Alive Settings

Directive Values Description
KeepAlive On | Off Enables or disables persistent connections.
KeepAliveTimeout 5 seconds (default) Number of seconds the server will wait for another request before closing the connection.
MaxKeepAliveRequests 100 (default) Maximum number of requests allowed per connection before closing the connection.

Example: Enabling Keep-Alive with Custom Settings

<IfModule mod_keepalive.c>
    KeepAlive On
    KeepAliveTimeout 15
    MaxKeepAliveRequests 200
</IfModule>
Note: Keep-Alive settings can significantly improve performance for sites with many small resources (like images, CSS, JS files) by reducing the overhead of repeatedly establishing new connections.

9. Setting MaxRequestWorkers Limit

Directive Values Description
MaxRequestWorkers 150 Maximum number of simultaneous requests that can be served
MaxRequestWorkers 256 Default value in Apache 2.4+

Example: Setting MaxRequestWorkers

<IfModule mpm_prefork_module>
    MaxRequestWorkers 256
</IfModule>
Note: Increasing MaxRequestWorkers can lead to higher memory usage and system load. Monitor server performance after adjustments.

10. Configuring ServerTokens

Directive Values Description
ServerTokens Full, Minor, Minimal, Prod, OS Controls the information included in the Server header sent by Apache

Example: Setting ServerTokens to Prod

ServerTokens Prod

Example: Setting ServerTokens to Full

ServerTokens Full
Note: ServerTokens Prod is recommended for production environments as it only reveals the Apache version without OS details.

11. Setting ServerSignature

Directive Values Description
ServerSignature Off, On, Full, Prod Determines whether the server adds a line with version information to server-generated error pages and directory listings.

Example: Configuring ServerSignature

<IfModule mod_server_signature.c>
    ServerSignature On
</IfModule>
Note: Setting ServerSignature to Full includes the full server version, while Prod omits version details for security reasons.

12. Understanding Global vs Local Directive Scope

Directive Scope Description
ServerRoot Global Defines the directory containing the server's configuration, error, and log files.
Listen Global Specifies the port and/or IP address on which the server listens for requests.
DocumentRoot Global Defines the directory from which the server serves documents.
Directory Local Defines a configuration context for a specific directory or path.
Files Local Applies configuration to specific files or file patterns.
Location Local Applies configuration to a specific URL path or pattern.
Note: Directives set in <Directory>, <Files>, or <Location> blocks override global settings for that scope.

Was this article helpful?