Enabling and Disabling a Website Running on Apache or NGINX

The instructions for disabling and re-enabling a website depend on the webserver that is installed for your web application.

Nginx and Apache are two most used web servers around the world. Approximate 80% of websites are hosted on these web servers.

Disabling and Enabling on the Nginx Web Server

By default, Nginx installed on Ubuntu and Debian systems use the sites-available and sites-enabled directories to control website access.

Ubuntu systems have a /etc/nginx/sites-available directory, which contains virtual host (vhost) files for each domain hosted.

For instance, the domain for example.com typically has a corresponding virtual host file named /etc/nginx/sites-available/www.example.com.conf. The filename might not include the .conf extension in all cases.

To enable a website, you must create a symbolic link inside the /etc/nginx/sites-enabled directory pointing to the actual vhost file in /etc/nginx/sites-available.

The nginx.conf file reviews the contents of the sites-enabled directory and determines which virtual host files to include. These domains are made available to potential viewers. Adding a symbolic link leading to a virtual host file enables the associated site while removing the symbolic link disables it.


include /etc/nginx/sites-enabled/*;

To find the name of the domain, list all of the sites with following command


ls /etc/nginx/sites-available

To disable a site, remove the symbolic link


sudo rm /etc/nginx/sites-enabled/example.com.conf

Reload Nginx to apply the change


sudo systemctl reload nginx

Use a browser to confirm the site no longer resolves. You should see an error page when you access the site.

To enable the site again


sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/example.com.conf

Disabling and Enabling on the Apache Web Server

On Ubuntu and other distributions of Linux, Apache makes it very easy to enable or disable a site. It includes utilities that handle all the necessary configuration changes.

Use the Apache Utilities: a2dissite and a2ensite

Disable the site using the a2dissite command followed by the site name. Enter the name used for the virtual host .conf file, without the extension.


a2dissite example.com

Reload the Apache configuration to apply the changes.


sudo systemctl reload apache2

Use a web browser to verify the domain is no longer accessible.

To re-enable the site again, use the a2ensite command followed by the site name.


a2ensite example.com

Reload the Apache configuration to apply the change.


sudo systemctl reload apache2
Use the Virtual Host File

If the a2dissite and a2ensite tools are not installed, edit the virtual host file and comment out the domain configuration.

Locate the virtual host file for the domain. If necessary, use the command httpd -S to display the path to this file. Change to the parent directory of the file, for example, /etc/httpd.


nano /etc/apache2/sites-available/000-default.conf

Comment out all lines in the virtual host file using the # symbol. The virtual host information typically begins with a line such as <VirtualHost *:80> followed by a list of the server attributes including ServerName and ServerAlias.


<VirtualHost *:80>
    ServerName example.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/web

    <Directory /var/www/html/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Reload Apache to apply the changes using systemctl restart. On CentOS, the Apache service is referred to as httpd.


sudo systemctl restart apache2

Try to access the domain using a web browser. The site should no longer resolve.

To re-enable the site, uncomment the contents of the .conf file. Remove the # symbols preceding each of the lines in the file.

Restart Apache using systemctl.