nginx,

Missing sites-available directory in Nginx

Aug 17, 2021 · 1 min read · Post a comment

As part of the Nginx series, in today’s tutorial, we are going to see on how to add that missing sites-available subdirectory. The reason behind this, is because most of us have been comfortable using Debian or Ubuntu, and the sites-available/sites-enabled logic is not used by the upstream packaging of Nginx by default.

Let’s see how can we implement this logic in the next few steps.

Prerequisites

  • Nginx
  • sudo privileges

Solution

Step 1. Create the missing subdirectories.

sudo mkdir -p /etc/nginx/{sites-available,sites-enabled}

Step 2. Open /etc/nginx/nginx.conf and add the following line in the http block:

http {
    . . .
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

Step 3. Create a vhost config file in sites-available subdirectory.

touch /etc/nginx/sites-available/default

Step 4. Once you add the configuration, create a soft link.

sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

Step 5. Test the Nginx configuration.

sudo nginx -t

Step 6. Restart the Nginx service.

sudo systemctl restart nginx

Conclusion

Although, sites-available/sites-enabled logic seems more convenient, as a best practice, use default conf.d, just because is a standard convention and can work anywhere. And, if you need to disable a site, you could just rename the config by adding a .disabled suffix. For instance:

sudo mv -i /etc/nginx/conf.d/default.conf{,.disabled}

If you need to re-enable it, just rename the file by removing the .disabled suffix.

sudo mv -i /etc/nginx/conf.d/default.conf{.disabled,}

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.