Sites Enabled with NGINX or Apache
NGINX and Apache are the two most widely used web servers in the world. Both are powerful, feature-rich, and highly configurable, making them the top choices for hosting websites. In Linux-based systems, NGINX and Apache handle website management by enabling and disabling websites using a system of configuration files, commonly referred to as sites-enabled and sites-available.
This article will guide you through the concepts of sites-enabled and sites-available, and explain how to enable and manage websites using NGINX and Apache web servers.
Understanding sites-available and sites-enabled
Both NGINX and Apache use a similar structure for managing websites. This structure separates the available sites from the enabled ones, allowing system administrators to easily manage which sites are live.
- sites-available: This directory contains configuration files for all the websites that you can potentially serve with your web server. The files in this directory define the virtual hosts or server blocks (in the case of NGINX) and their configurations. These websites are not active until they are enabled.
- sites-enabled: This directory contains symbolic links to the configuration files of websites that are currently enabled and being served by the web server. Only sites that have been “enabled” will be active and available to users.
Managing Sites with Apache
1. Apache Virtual Hosts Configuration
Apache uses virtual hosts to serve multiple websites from a single server. Each website has its own configuration file, which specifies how Apache should handle the domain, including directives like the document root, logs, and more.
Example Virtual Host Configuration File for Apache
You can create a virtual host configuration file in the /etc/apache2/sites-available/ directory. For example, to configure a website called example.com:
Inside the file, you would define the configuration for example.com:
<VirtualHost *:80>
ServerAdmin admin@test.oo.md
ServerName (your_domain or Ip_address)
ServerAlias www.test.oo.md
DocumentRoot /var/www/test.oo.md
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
*ServerName (your_domain or Ip_address) – replace your_domain value which you use also for Ip_address.
2. Enable the Site
Once the virtual host configuration file is created, you can enable the site using the a2ensite command (Apache 2 Enable Site):