Apache Configuration for Ubuntu and Debian
Apache is a powerful and modular web server that runs more than half of the websites on the internet. In this guide, you will learn Apache's file hierarchy, global settings, virtual host configurations and module management step by step.
What Will You Learn in This Guide?
- How the Apache file structure works
- How to optimize global settings
- Creating and managing Virtual Host
- Enable/disable modules
- How to customize Apache for your own projects
1. Getting to Know Apache File Structure
Apache keeps its configuration files in the /etc/apache2/ directory.
To list:
ls -f /etc/apache2
This command lists the Apache configuration folder.
1.1 Important directories
apache2.conf → Main global configuration file ports.conf → Port definitions sites-available/ → Virtual host stubs sites-enabled/ → Active virtual hosts mods-available/ / mods-enabled/ → Apache modules conf-available/ / conf-enabled/ → Additional configuration files
Apache uses a modular architecture rather than a single monolith configuration file.
2. Examining the apache2.conf File
Open the main configuration file:
sudo nano /etc/apache2/apache2.conf
This file contains the following settings:
Global Apache ayarları
Modüllerin yüklenme kuralları
VirtualHost yapılandırmalarının dahil edilmesi
Örnek yapılandırma
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
This structure allows Apache to load all configuration files dynamically.
3. Editing Global Apache Settings
###Timeout
Default value:
Timeout 300
On most systems, 30–60 seconds is more appropriate.
###KeepAlive
When KeepAlive is on, multiple HTTP requests can be processed over a single connection.
KeepAlive On
MaxKeepAliveRequests
Default:
MaxKeepAliveRequests 100
The value 0 means sınırsız.
###KeepAliveTimeout
The amount of time the server will wait for the new request.
KeepAliveTimeout 5
Checking MPM (Multi-Processing Module) Type
a2query -M
Sample output:
event
The MPM module determines how Apache manages connections.
4. Virtual Host Configuration
Open the default hosts file:
sudo nano /etc/apache2/sites-available/000-default.conf
Example VirtualHost:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
</VirtualHost>
4.1 Creating a Virtual Host for Your Own Domain
Create a new VirtualHost:
sudo nano /etc/apache2/sites-available/ornek.com.conf
Example configuration:
<VirtualHost *:80>
ServerName ornek.com
ServerAlias www.ornek.com
DocumentRoot /var/www/ornek.com/public_html
</VirtualHost>
5. Directory Rules (Directory)
An example directory configuration in apache2.conf:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
This block determines directory access permissions.
Alias and ScriptAlias
Alias
It is used to publish a static directory under a different URL.
Alias "/icerik/" "/usr/local/apache/icerik/"
ScriptAlias
Specifies the directory where CGI scripts will be run.
ScriptAlias "/cgi-bin/" "/usr/lib/cgi-bin/"
6. Enabling Sites and Modules
Activating the site:
sudo a2ensite ornek.com.conf
Disabling the site:
sudo a2dissite 000-default
Activate module:
sudo a2enmod rewrite
Disable module:
sudo a2dismod rewrite
Restarting Apache:
sudo systemctl restart apache2
This command applies the changes made.
Frequently Asked Questions (FAQ)
What does a2ensite do?
Activates a VirtualHost configuration file.
What does AllowOverride None mean?
Prevents .htaccess files from changing the configuration.
Why is Apache MPM important?
It determines how the server handles concurrent connections and directly affects performance.
Why is there more than one Virtual Host on a server?
To host multiple websites with a single IP address.
What is the difference between Alias and ScriptAlias? Alias redirects static files ScriptAlias is used for executable CGI scripts
Result
With this guide, you learned Apache's modular architecture, file structure, global settings and virtual host management.
Now you can optimize Apache for your own projects and easily host different websites on a single server.
You can achieve high performance for your projects by testing these configurations on the GenixNode platform.

