0
0
NginxComparisonBeginner · 3 min read

Sites-Available vs Sites-Enabled in Nginx: Key Differences and Usage

In Nginx, sites-available holds all server configuration files, while sites-enabled contains symbolic links to the active configurations. This setup lets you easily enable or disable sites by adding or removing links without deleting config files.
⚖️

Quick Comparison

Here is a quick table comparing sites-available and sites-enabled directories in Nginx:

Aspectsites-availablesites-enabled
PurposeStores all server config files, active or inactiveStores symbolic links to active config files only
Content TypeFull Nginx server block config filesSymbolic links pointing to files in sites-available
Effect on NginxNo direct effect until linkedControls which sites Nginx loads and serves
ModificationAdd or edit config files hereAdd or remove symlinks to enable/disable sites
Typical UsageKeep all site configs organizedActivate or deactivate sites without deleting configs
⚖️

Key Differences

The sites-available directory is like a storage shelf where you keep all your Nginx server configurations. These files define how Nginx should handle different websites or services, but just having them here does not make Nginx use them.

On the other hand, sites-enabled acts like a display rack showing which configurations are currently active. It contains symbolic links (shortcuts) that point to the actual config files in sites-available. Nginx reads only the files linked here when it starts or reloads.

This separation allows you to prepare or keep multiple site configs without affecting the live server. You can enable a site by creating a symlink in sites-enabled or disable it by removing the symlink, all without deleting the original config file.

⚖️

Code Comparison

Here is an example of a server configuration file stored in sites-available for a simple website:

nginx
server {
    listen 80;
    server_name example.com www.example.com;

    root /var/www/example.com/html;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
}
↔️

sites-enabled Equivalent

To enable the above site, you create a symbolic link in sites-enabled pointing to the config file in sites-available. This command does that:

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

When to Use Which

Use sites-available to store and edit all your Nginx site configurations safely. It is your workspace for preparing site setups.

Use sites-enabled to control which sites Nginx actually serves. Enable a site by linking it here, and disable it by removing the link. This method avoids deleting configs and makes managing multiple sites simple and safe.

Key Takeaways

Keep all Nginx site configs in sites-available for organization and safety.
Enable sites by creating symbolic links in sites-enabled to activate them.
Disable sites by removing their links from sites-enabled without deleting files.
Nginx reads only configs linked in sites-enabled when starting or reloading.
This setup makes managing multiple sites easy and reduces risk of config loss.