Skip to main content

Configuration

The Apache HTTP Server is highly configurable, allowing you to customize its behavior to suit your specific needs. The main configuration file is httpd.conf, and additional configurations can be made through various other files and directories

The Httpd.conf

  • The httpd.conf file is the primary configuration file for Apache. It is typically located in the /etc/apache2/ directory on Ubuntu systems. This file contains directives that control various aspects of Apache's behavior, such as server settings, logging, and module configurations

  • This is the main Apache server configuration file.

  • It contains the configuration directives that control the operation of Apache.

Define the server name and port

  • ServerName (example.com) Listen 80

Define the document root directory

DocumentRoot "/var/www/html"

Define the logging configuration

LogLevel warn ErrorLog "/var/log/apache2/error.log" CustomLog "/var/log/apache2/access.log" combined

Load necessary modules

LoadModule ...

Directory Configuration

  • Apache allows you to configure settings specific to directories or locations within your web server's document root. These configurations are typically placed in the
<!-- <Directory> block within the httpd.conf file or in separate .htaccess files. -->
<!-- <Directory "/var/www/html"> -->
  • Options FollowSymLinks

  • AllowOverride None

<!-- Require all granted </Directory> -->
  • The .htaccess files are used to override or add configurations for specific directories within the document root. These files are typically used for URL rewriting, access control, and other directory-level settings

Virtual Hosts

  • Apache supports virtual hosting, which allows you to serve multiple websites or applications from a single server. Virtual hosts are defined in the httpd.conf file or in separate configuration files within the /etc/apache2/sites-available/ and /etc/apache2/sites-enabled/ directories
image-20240314-103427.png

Modules

  • Apache's functionality can be extended through the use of modules. Modules are loaded and configured within the httpd.conf file or in separate configuration files within the /etc/apache2/mods-available/ and /etc/apache2/mods-enabled/ directories.

Load the necessary modules

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
 LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so

After making any configuration changes, you'll need to restart the Apache service for the changes to take effect

sudo systemctl restart apache2
  • Apache's extensive configuration options allow you to customize the server to meet your specific requirements, from server settings and virtual hosts to modules and directory-level configurations