If you’re used to working with Nginx on Debian 12, you’ve likely mastered the sites-available
and sites-enabled
directory structure to manage virtual hosts. Interestingly, Apache2 adopts the same concept , just with a few differences in how things are enabled and maintained.
This article walks through setting up Apache2 and draws parallels to the Nginx workflow, so you can feel right at home.
Apache2 Directory Structure
Apache’s site configuration lives in two primary directories:
/etc/apache2/sites-available/
: Where all virtual host config files reside./etc/apache2/sites-enabled/
: Where symbolic links to active configs live.
Just like Nginx, only the files symlinked into sites-enabled
are actually loaded by the server.
Enabling Sites, Apache vs Nginx
With Nginx:
You manually enable sites using symlinks:
0 1 2 |
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ |
And disable them by removing the link:
0 1 2 |
sudo rm /etc/nginx/sites-enabled/example.com |
With Apache,
Apache provides helper commands to manage this:
0 1 2 3 |
sudo a2ensite example.com.conf sudo a2dissite example.com.conf |
These commands create or remove symlinks from sites-enabled
, just like you’d do manually in Nginx.
After any change, reload the config:
0 1 2 |
sudo systemctl reload apache2 |
Example Virtual Host File in Apache
Let’s say you want to host example.com
. Here’s a basic config file:
/etc/apache2/sites-available/example.com.conf
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<VirtualHost *:80> ServerName example.com DocumentRoot /var/www/example.com <Directory /var/www/example.com> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/example_error.log CustomLog ${APACHE_LOG_DIR}/example_access.log combined </VirtualHost> |
To activate it:
0 1 2 3 |
sudo a2ensite example.com.conf sudo systemctl reload apache2 |
Make sure the directory /var/www/example.com
exists and contains your site files.
Apache vs Nginx, Side-by-Side
Feature | Nginx | Apache2 |
---|---|---|
Engine | Event-driven | Process/thread-based |
Enabling sites | Manual symlink | a2ensite , a2dissite |
Module system | Edit config manually | a2enmod , a2dismod |
.htaccess support | Not supported | Supported (if enabled) |
Config reload | systemctl reload nginx | systemctl reload apache2 |
Why Switch or Use Both?
Apache2 and Nginx each have strengths:
- Apache is easier for
.htaccess
users, legacy systems, and dynamic PHP apps. - Nginx excels in performance and is great as a reverse proxy or static file server.
In some setups, you may even use both — with Nginx in front as a reverse proxy and Apache handling backend logic.
Final Thoughts
If you’re comfortable with Nginx on Debian, you’ll find Apache2’s structure familiar. Tools like a2ensite
and a2enmod
make managing configurations easy, especially when you’re dealing with multiple domains or legacy apps that rely on .htaccess
.
Whether you’re exploring Apache for compatibility reasons, migrating from Nginx, or just curious, this transition is smooth , and sometimes, even fun.