Apache HTTP Server Overview and Configuration
Apache HTTP Server (httpd) is the world's most widely used open-source web server software. On Debian/Ubuntu-based systems it is installed as the apache2 package; on RHEL/AlmaLinux-based systems it is installed as httpd. Configuration files can be split and managed per module and per virtual host. On Ubuntu-based systems, a2ensite / a2dissite enable and disable per-site configuration, while on RHEL-based systems the Include directive is used.
Syntax
# ===============================================
# Basic structure of httpd.conf / apache2.conf
# ===============================================
# -----------------------------------------------
# Global settings (applied to the entire server)
# -----------------------------------------------
# Specifies the user and group under which Apache runs.
# www-data is common on Ubuntu-based systems; apache is common on RHEL-based systems.
User www-data
Group www-data
# Sets the server administrator's email address.
# Displayed on error pages.
ServerAdmin gojo@jujutsu-tech.example.jp
# Explicitly specifies the server's hostname and port.
# Auto-detection is used if omitted, but explicit specification is recommended.
ServerName jujutsu-tech.example.jp
# Prevents the server version from being included in response headers.
# Prod (product name only) is recommended for security.
ServerTokens Prod
ServerSignature Off
# -----------------------------------------------
# Default document root settings
# -----------------------------------------------
# Specifies the root directory where the website's files are stored.
DocumentRoot /var/www/html
# Configures access control for the DocumentRoot.
<Directory /var/www/html>
# Controls how much .htaccess files can override server configuration.
# None: fully disabled / FileInfo: MIME types etc. / All: everything allowed
AllowOverride All
# Sets the access control evaluation order.
# Require all granted: allows access from all clients.
Require all granted
</Directory>
# -----------------------------------------------
# Ubuntu-based: sites-available structure
# -----------------------------------------------
# /etc/apache2/
# ├── apache2.conf ← main configuration file
# ├── ports.conf ← ports to listen on
# ├── mods-available/ ← available modules (.load / .conf)
# ├── mods-enabled/ ← symbolic links to enabled modules
# ├── sites-available/ ← available virtual host configuration files
# │ ├── 000-default.conf ← default site configuration
# │ └── itadori-app.conf ← additional site configuration (example)
# ├── sites-enabled/ ← symbolic links to enabled sites
# │ └── itadori-app.conf -> ../sites-available/itadori-app.conf
# └── conf-available/ ← other configuration fragments
# -----------------------------------------------
# Basic structure of VirtualHost directive
# -----------------------------------------------
# <VirtualHost *:80> defines a virtual host on port 80.
# * means all IP addresses.
<VirtualHost *:80>
# Specifies the domain name this virtual host responds to.
ServerName example.jp
# Specifies additional domain names (aliases) for this virtual host.
ServerAlias www.example.jp
# Specifies the document root for this virtual host.
DocumentRoot /var/www/example
# Specifies the file path for error log output.
ErrorLog ${APACHE_LOG_DIR}/example-error.log
# Specifies the file path and format for access log output.
# combined: IP address, date/time, request, status, bytes, referrer, user agent
CustomLog ${APACHE_LOG_DIR}/example-access.log combined
</VirtualHost>
Directive / Command Reference
| Directive / Command | Description |
|---|---|
ServerName {domain} | Specifies the hostname of the server or virtual host. Used for request routing. |
ServerAlias {domain} ... | Sets additional domain names (aliases) for a virtual host. Useful for handling both www and non-www variants. |
ServerAdmin {email} | Sets the server administrator's email address. Displayed on error pages. |
DocumentRoot {path} | Specifies the root directory where the website's files are stored. |
<Directory {path}> ... </Directory> | Sets access control and options for a specific directory in block form. |
AllowOverride {value} | Specifies the scope of configuration overrides allowed by .htaccess files. Accepts None (disabled), All (everything allowed), FileInfo, and others. |
Require all granted | Allows access from all clients. Use Require all denied to deny all access instead. |
ErrorLog {path} | Specifies the output file for error logs. ${APACHE_LOG_DIR} is an environment variable that typically resolves to /var/log/apache2. |
CustomLog {path} {format} | Specifies the output file and format for access logs. combined is the most commonly used format. |
<VirtualHost *:80> | Defines a virtual host block for port 80. Use *:443 for HTTPS. |
a2ensite {config-file} | On Ubuntu-based systems, creates a symbolic link from sites-available/ to sites-enabled/ to activate a configuration file. |
a2dissite {config-file} | On Ubuntu-based systems, disables a virtual host configuration by removing its symbolic link. |
a2enmod {module} | On Ubuntu-based systems, enables an Apache module such as mod_rewrite or mod_ssl. |
a2dismod {module} | On Ubuntu-based systems, disables an Apache module. |
apachectl configtest | Checks the configuration file syntax. If the output shows Syntax OK, the configuration is valid. |
Examples
/etc/apache2/sites-available/itadori-app.conf
# -----------------------------------------------
# Virtual host configuration for Itadori's app
# Domain: itadori-app.jujutsu-tech.example.jp
# -----------------------------------------------
<VirtualHost *:80>
# Sets the domain name this virtual host responds to.
ServerName itadori-app.jujutsu-tech.example.jp
# Handles both www and non-www variants.
ServerAlias www.itadori-app.jujutsu-tech.example.jp
# Sets the administrator's email address (displayed on error pages).
ServerAdmin yuji.itadori@jujutsu-tech.example.jp
# Specifies the document root for the app.
DocumentRoot /var/www/itadori-app/public
# Configures access control for the document root.
<Directory /var/www/itadori-app/public>
# Set to All when using .htaccess for URL rewriting (e.g., WordPress or Laravel).
AllowOverride All
# Allows access from all clients.
Require all granted
# Sets the directory index (priority order for index.html / index.php).
DirectoryIndex index.php index.html
</Directory>
# Settings for PHP-FPM integration (requires mod_proxy_fcgi).
# <FilesMatch "\.php$">
# SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost/"
# </FilesMatch>
# Outputs error logs to a site-specific file.
ErrorLog ${APACHE_LOG_DIR}/itadori-app-error.log
# Outputs access logs in combined format.
CustomLog ${APACHE_LOG_DIR}/itadori-app-access.log combined
</VirtualHost>
# -----------------------------------------------
# HTTPS redirect configuration
# Redirects HTTP requests to HTTPS.
# (See ssl_overview.php for SSL configuration.)
# -----------------------------------------------
# <VirtualHost *:80>
# ServerName itadori-app.jujutsu-tech.example.jp
# Redirect permanent / https://itadori-app.jujutsu-tech.example.jp/
# </VirtualHost>
$ sudo apachectl configtest
Syntax OK
$ sudo a2ensite itadori-app.conf
Enabling site itadori-app.
To activate the new configuration, you need to run:
systemctl reload apache2
$ sudo systemctl reload apache2
$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2026-03-25 10:00:00 UTC; 3s ago
$ curl -I http://itadori-app.jujutsu-tech.example.jp/
HTTP/1.1 200 OK
Server: Apache
Content-Type: text/html; charset=UTF-8
Enabling mod_rewrite and setting rewrite rules in .htaccess
# -----------------------------------------------
# Enabling the mod_rewrite module
# Required for URL rewriting (e.g., /user/gojo → index.php?id=gojo).
# -----------------------------------------------
# Enable mod_rewrite (Ubuntu-based systems).
sudo a2enmod rewrite
# Restart Apache to apply the changes.
sudo systemctl restart apache2
# -----------------------------------------------
# Contents of /var/www/itadori-app/public/.htaccess
# -----------------------------------------------
# Enable the mod_rewrite engine.
# RewriteEngine On
# Only rewrite if the requested file or directory does not exist.
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# Forward all requests to index.php (front controller pattern).
# RewriteRule ^ index.php [QSA,L]
$ sudo a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: systemctl restart apache2 $ sudo systemctl restart apache2
Configuration on RHEL/AlmaLinux-based systems (place files in /etc/httpd/conf.d/)
# ----------------------------------------------- # Configuration file location on RHEL/AlmaLinux-based systems. # Files placed in /etc/httpd/conf.d/ are loaded automatically. # The a2ensite command is not needed. # ----------------------------------------------- # Create the configuration file. sudo vi /etc/httpd/conf.d/nanami-app.conf # ----------------------------------------------- # Contents of /etc/httpd/conf.d/nanami-app.conf # Virtual host configuration for Nanami's app # ----------------------------------------------- # <VirtualHost *:80> # ServerName nanami-app.jujutsu-tech.example.jp # ServerAdmin kento.nanami@jujutsu-tech.example.jp # DocumentRoot /var/www/nanami-app/public # # <Directory /var/www/nanami-app/public> # AllowOverride All # Require all granted # </Directory> # # ErrorLog /var/log/httpd/nanami-app-error.log # CustomLog /var/log/httpd/nanami-app-access.log combined # </VirtualHost> # Check the syntax and then restart httpd. sudo apachectl configtest sudo systemctl restart httpd
$ sudo apachectl configtest
Syntax OK
$ sudo systemctl restart httpd
$ sudo systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2026-03-25 10:05:00 UTC; 2s ago
Overview
Apache HTTP Server has been in active development since 1995. It is known for its flexible per-directory configuration via .htaccess and its rich module ecosystem (mod_rewrite, mod_ssl, mod_proxy, and more). On Ubuntu-based systems, the standard workflow is to create a configuration file in sites-available/ and enable it with a2ensite, making it easy to manage multiple sites on a single server. On RHEL/AlmaLinux-based systems, placing a file in /etc/httpd/conf.d/ is all that is needed for it to be loaded automatically. After making configuration changes, always run apachectl configtest to check the syntax, then apply the changes with systemctl reload apache2 (or httpd). Enabling HTTPS requires configuring mod_ssl and a certificate (see SSL / TLS configuration). Nginx, known for its lightweight design and high concurrency, is also widely used as an alternative to Apache. Use systemctl to manage service start, stop, and autostart.
If you find any errors or copyright issues, please contact us.