Debug School

rakesh kumar
rakesh kumar

Posted on

Apache web server configuration files

configuration-files
apache-configuration-files
apache-web-server-configuration-files
configuring apache

Apache webserver reads its configuration files every time it's started. The configuration files are in plain text format, and Apache will need to restart every time there are changes in the configuration file for the changes to take effect.

Apache's primary configuration file location is set during compilation and is set differently between distributions. The configuration is usually split into multiple files for ease of management and separation of concern. It will then be called from the main configuration file using Include and IncludeOptional directives.

You can always check the location of the primary configuration file by running the Apache binary for your distribution with the -V option and then looking for the SERVER_CONFIG_FILE value.

Image description
Image description
![Image description]

(https://www.debug.school/uploads/articles/mew1f7hzi26undkl84su.png)

Default Apache configuration location
The location of Apache's main configuration file is different for most distributions, and they are also split differently. The following table lists how the configuration file is managed for different distributions:

Image description

Image description

Image description
Image description

Default Apache configuration value
Apart from using a different location for the main configuration file, different distributions also use different values for Apache configuration options.

The table below lists some of the default configuration values for Apache on different distributions.

see image

Path for files and directories are relative to the Base directory if it doesn't start with a /; e.g. modules/ for CentOS's module directory translates to /etc/httpd/modules/.

Absolute paths which start with /, such as Ubuntu's module location, are based on the root directory.

Kinds of Configuration Files
There are various kinds of configuration files. Some of them are:

Image description
Image description

httpd.conf Configuration File

  1. The httpd.conf is a configuration file.
  2. It is used by the Apache HTTP Server.
  3. Apache server looks at this file for different configuration properties.
  4. It is stored in path : /etc/httpd/conf/httpd.conf.
  5. The default configuration of httpd.conf includes all types of directives and it works well for most systems.
    *How to edit httpd.conf file *?

  6. Copy the original file to some other file and create a backup. This will help you recover any mistakes while editing the file.

  7. If any mistakes are found in httpd.conf file, the web server will not work properly.

  8. To edit httpd.conf file open the file through editor like “vi editor”, so that you can make changes in it.

  9. After editing, reload the file or stop and start httpd process.

  10. To reload the server configuration file type use /service httpd reload command.

  11. To start the server configuration file type use /service httpd start command.

  12. To stop the server configuration file type use /service httpd stop command.

  13. To restart (stop and start) the server configuration file type use /service httpd restart command.

If web server does not work properly, then you have made some typo mistakes. Check the latest entries in the web server's error log stored at /var/log/httpd/error_log to see the errors.
Configuration Directives in httpd.conf
ServerRoot
It specifies the top level directory containing website content. Both your secure and non-secure servers are set to ServerRoot of “/etc/httpd”.

PidFile
PidFile names the file where server stores its process ID (Pid). By default, pid is listed in /var/run/httpd.pid.

LockFile
It sets the path to the lockfile. It is used when httpd is compiled with either USE_FCNTL_SERIALIZED_ACCEPT or USE_FLOCK_SERIALIZED_ACCEPT.

Timeout
Timeout sets the amount of time in seconds that your server will wait for response and transmissions during communications. By default, it is set to 300 seconds, which is appropriate for most situations.

# KeepAlive: Enable/disable persistent connections
KeepAlive On


# MaxKeepAliveRequests: How many requests to allow during a persistent connection. 
# You can set it 0 for unlimited requests, but it is not recommended.
MaxKeepAliveRequests 100



# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection. Default is 5 seconds
KeepAliveTimeout 15
Enter fullscreen mode Exit fullscreen mode

KeepAlive
It sets whether the server allows more than one request per connection and can be used to prevent a client from using too much of the servers resources. By default, KeepAlive is set to off that means server does not allow continuous connections.

MaxKeepAliveRequests
MaxKeepAliveRequests sets the maximum number of requests allowed per persistent connections. It is set to 100 by default, which should be suitable for most situations.

KeepAliveTimeout
This directive sets the number of seconds your server will wait for next request, after a request has been served before it closes the connection. By default, it is set to 15 seconds.

StartServers
This directive sets how many server processes are created upon startup. The Web server is set to start 8 server processes at startup.

**MaxClients
**Maxclients sets a limit on the total number of server processes that can run simultaneously at one time. The main purpose of this directive is to keep a runaway web server from crashing the operating system. By default, it is set to 150.

LoadModule
This directive is used to load in Dynamic Shared Object (DSO) modules. The order of modules is important.

User
It sets the userid used by the server to answer the requests. User is not allowed to execute any code that is not intended to be in response to HTTP requests. By default, User is set to Apache.

Group
It is similar to the User. The Group sets the groupid under which the server will answer requests. By default, Group is set to Apache.

ServerName
It specifies a hostname and port number for the server. ServerName which is different from the server's real host name. ServerName must be a valid DNS (Domain Name Service).

Options
It controls which server features are available in a particular directory. By default, it is set to 'FollowSymLinks' which means that server is allowed to follow symbolic links in the root directory.

Allow
Allow specifies which requester can access a given directory. The requester can be all, an IP address, a domain name, a partial IP address, a network/netmask pair. By default, it is set to all.

Deny
Deny is similar to Allow. It specifies which requester is denied from access. The requester can be all, an IP address, a domain name, a partial IP address, a network/netmask pair.

LogLevel
LogLevel can be set from least verbose to most verbose. It sets how verbose the error messages in the error logs can be.

LogFormat
LogFormat sets up a format for the messages in your access log.

CustomLog
CustomLog identifies the log file and its log file format.

ServerSignature
This directive adds line containing the Apache server version and ServerName of the serving host to any server generated documents. The default ServerSignature is set to 'On'.

AddType
AddType directive is used to define MIME type and file extension pairs. For instance, web server identifies .php4, .php3, .phtml, .php as PHP MIME types.

AddHandler
This directive maps file extensions to specific handlers.

For Example
The cgi-script handler is matched with an extension .cgi for which the format is
AddHandler cgi-script .cgi

Action
It contains a MIME content type and CGI script pair, so that if a file of that media type is requested, a particular CGI script is executed.

Top comments (0)