Sites-Available vs Sites-Enabled in Nginx: Key Differences and Usage
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:
| Aspect | sites-available | sites-enabled |
|---|---|---|
| Purpose | Stores all server config files, active or inactive | Stores symbolic links to active config files only |
| Content Type | Full Nginx server block config files | Symbolic links pointing to files in sites-available |
| Effect on Nginx | No direct effect until linked | Controls which sites Nginx loads and serves |
| Modification | Add or edit config files here | Add or remove symlinks to enable/disable sites |
| Typical Usage | Keep all site configs organized | Activate 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:
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:
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.