Updated: 12 October 2026 · Applies to: Apache 2.4.66 on Ubuntu 26.04, 2.4.58 on Ubuntu 24.04, 2.4.68 on Debian 13; httpd 2.4.63 on AlmaLinux 10.2 and 2.4.62 on Rocky Linux 9.8 (same steps on RHEL 9 and 10)

To disable a site in Apache on Ubuntu or Debian, run a2dissite with the site's file name from /etc/apache2/sites-available (without .conf) and reload Apache. AlmaLinux, Rocky Linux and RHEL have no a2dissite: rename the site's file in /etc/httpd/conf.d so it no longer ends in .conf, then reload httpd.

# Ubuntu and Debian
a2dissite example.com
systemctl reload apache2

# AlmaLinux, Rocky Linux and RHEL
mv /etc/httpd/conf.d/example.com.conf /etc/httpd/conf.d/example.com.conf.disabled
systemctl reload httpd

Disabling a site does not make its domain return an error. In our tests, Apache answered requests for the disabled domain with the default site, or with the default welcome page when no site was left. The sections below show how to prevent that and how to remove the welcome page itself.

Disable a site on Ubuntu and Debian (a2dissite)

  1. List the enabled sites:
    $ a2query -s
    000-default (enabled by site administrator)
    example.com (enabled by site administrator)
    If the site has a separate HTTPS file, it is listed too: disable both.
  2. Disable the site:
    $ a2dissite example.com
    Site example.com disabled.
    To activate the new configuration, you need to run:
      service apache2 reload
    systemctl reload apache2 does the same. If the name is wrong you get ERROR: Site example does not exist!; run ls /etc/apache2/sites-available for the exact names.
  3. Check the configuration and reload:
    apache2ctl configtest
    systemctl reload apache2
  4. Confirm which sites Apache now serves with apache2ctl -S.

a2dissite only removes the link in /etc/apache2/sites-enabled. The file stays in sites-available, so a2ensite example.com and a reload bring the site back. To turn off the default site, the name is 000-default (and default-ssl for HTTPS, which is disabled on a fresh install).

Disable a site on AlmaLinux, Rocky Linux and RHEL

The main configuration, /etc/httpd/conf/httpd.conf, ends with IncludeOptional conf.d/*.conf, so Apache reads every file in /etc/httpd/conf.d whose name ends in .conf and ignores the rest.

  1. Find the file that defines the site: httpd -S lists each virtual host with its file and line.
  2. Rename it:
    mv /etc/httpd/conf.d/example.com.conf /etc/httpd/conf.d/example.com.conf.disabled
  3. Test and reload:
    apachectl configtest
    systemctl reload httpd
  4. To enable the site again, rename it back to .conf and reload.

Do not delete welcome.conf, autoindex.conf or userdir.conf from that folder: they belong to the httpd package and come back with updates.

Where requests for a disabled site go

According to the Apache documentation, when no ServerName or ServerAlias matches, "the first listed virtual host" is used. Requests that match no virtual host at all are answered by the main server configuration. What we saw on Ubuntu 26.04 with two sites, 000-default and site1.example.com:

  • After a2dissite 000-default, requests for the server IP and any unknown name returned the page of site1.example.com, because it was now the first site.
  • After disabling both, every request returned "Apache2 Ubuntu Default Page: It works" with status 200: the main configuration still serves /var/www/html.

So a disabled domain that still points to your server shows another customer's site or the default page. To return an error instead, add a catch-all site that loads first. On Ubuntu and Debian, create /etc/apache2/sites-available/000-catchall.conf:

<VirtualHost *:80>
    ServerName catchall.invalid
    <Location "/">
        Require all denied
    </Location>
</VirtualHost>

Then run a2ensite 000-catchall and reload. On AlmaLinux, Rocky Linux and RHEL, save the same block as /etc/httpd/conf.d/000-catchall.conf and reload. In our tests on Debian 13 and AlmaLinux 10.2, apache2ctl -S and httpd -S then showed default server catchall.invalid; the IP and unknown names got 403 Forbidden while site1.example.com still worked. The same rule applies to HTTPS: the first *:443 site answers names that match no other HTTPS site.

Remove the default welcome page

Ubuntu and Debian: the default page is a real file, /var/www/html/index.html. Replace it with your own page or delete it. If you delete it and leave the folder empty, Apache lists the folder's contents, because the <Directory /var/www/> block in /etc/apache2/apache2.conf has Options Indexes FollowSymLinks. Change that line to:

Options -Indexes +FollowSymLinks

Then run apache2ctl configtest and systemctl reload apache2. In our test the empty folder then returned 403 Forbidden.

AlmaLinux, Rocky Linux and RHEL: the test page ("Test Page for the HTTP Server on AlmaLinux", "HTTP Server Test Page powered by: Rocky Linux") is shown by /etc/httpd/conf.d/welcome.conf whenever /var/www/html has no index file. In our test it came with status 403, not 200.

  1. Best: publish your own /var/www/html/index.html (or index.php). The test page is then never used.
  2. If the folder must stay empty, first turn off folder listings. In /etc/httpd/conf/httpd.conf, inside <Directory "/var/www/html">, change Options Indexes FollowSymLinks to Options -Indexes +FollowSymLinks.
  3. Comment out every line of welcome.conf. Do not delete it: the file itself says it "will be restored on upgrades".
    sed -i 's/^/#/' /etc/httpd/conf.d/welcome.conf
    apachectl configtest
    systemctl reload httpd

Order matters: in our test, commenting out welcome.conf while Indexes was still on returned "Index of /" (a file listing). With -Indexes it returned 403 Forbidden.

Stop Apache completely

If you meant to switch off the web server itself rather than one site, stop it and keep it from starting at boot with systemctl disable --now apache2 (Ubuntu, Debian) or systemctl disable --now httpd (AlmaLinux, Rocky Linux, RHEL).

Related guides: install Apache on Ubuntu and set up a virtual host, basic Apache configuration (virtual hosts, files and logs) and hide the Apache version number.

Official documentation: Apache name-based virtual hosts and the Options directive.

Hai trovato utile questa risposta?

Ti serve ancora aiuto? Apri un ticket