Post Date: April 3, 2021
Last Updated: December 01, 2026
Introduction
When installing Nginx on CentOS 7, you may notice that the Nginx sites-available directory is missing from the default /etc/nginx/ configuration directory. This can make managing virtual hosts different from the standard Ubuntu and Debian Nginx configuration structure.
Unlike Ubuntu and Debian, the default Nginx installation on CentOS 7 generally uses the conf.d directory to manage additional server configuration files. However, if you prefer the sites-available and sites-enabled directory structure, you can manually create and configure these directories.
In this guide, we will explain how to create the missing Nginx directories, configure the main Nginx configuration file, enable virtual hosts using symbolic links, and alternatively manage virtual host configurations directly through the conf.d directory.
Why Are Sites-Available and Sites-Enabled Directories Missing in Nginx?
The sites-available and sites-enabled directories are not included by default in every Nginx installation.
These directories are commonly used in Debian and Ubuntu-based distributions:
- sites-available: Stores all available virtual host configuration files.
- sites-enabled: Contains symbolic links to the virtual host configurations that should be active.
On CentOS 7, Nginx typically uses the /etc/nginx/conf.d/ directory to load additional configuration files.
You can manually configure the sites-available and sites-enabled directories by following the steps below.
How to Create Sites-Available and Sites-Enabled Directories in Nginx on CentOS 7
Step 1: Create the Missing Directories
First, create the sites-available and sites-enabled directories inside the Nginx configuration directory.
Run the following commands:
mkdir -p /etc/nginx/sites-available mkdir -p /etc/nginx/sites-enabled

Set the appropriate directory ownership and permissions:
chown -R root:root /etc/nginx/sites-available chown -R root:root /etc/nginx/sites-enabled chmod 755 /etc/nginx/sites-available chmod 755 /etc/nginx/sites-enabled
These directories will now be available for managing your Nginx virtual host configuration files.

Step 2: Configure the Nginx Main Configuration File
Open the main Nginx configuration file:
vi /etc/nginx/nginx.conf
Locate the http block and add the following include directive inside it:
include /etc/nginx/sites-enabled/*;
Example configuration:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Save the file and exit the editor.
Note: If your existing configuration already includes the conf.d directory, do not add the same include directive again.

Step 3: Create a Virtual Host Configuration File
Now, create a separate virtual host configuration file inside the sites-available directory.
For example:
vi /etc/nginx/sites-available/example.com
Add the following sample configuration:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
Replace example.com with your actual domain name and update the document root according to your website directory.
Save the configuration file.

Step 4: Enable the Virtual Host Using a Symbolic Link
To activate the virtual host, create a symbolic link from the sites-available directory to the sites-enabled directory.
Run:
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
This allows you to maintain all virtual host configurations in sites-available and enable or disable individual websites through symbolic links.
Before applying the configuration, test the Nginx configuration:
nginx -t
If the configuration is valid, reload Nginx:
systemctl reload nginx
If necessary, you can restart the service using:
systemctl restart nginx
Your virtual host configuration should now be active.

Alternative Method: Use the Conf.d Directory Without Symbolic Links
If you do not want to manage virtual host configurations using sites-available and sites-enabled, you can use the default Nginx conf.d directory.
This is the standard approach commonly used in CentOS 7 Nginx installations.
Step 1: Create the Conf.d Directory
Check whether the directory already exists:
ls -ld /etc/nginx/conf.d
If it does not exist, create it:
mkdir -p /etc/nginx/conf.d
Set the appropriate permissions:
chown root:root /etc/nginx/conf.d chmod 755 /etc/nginx/conf.d

Step 2: Configure the Nginx Include Directive
Open the Nginx configuration file:
vi /etc/nginx/nginx.conf
Inside the http block, make sure the following include directive is present:
include /etc/nginx/conf.d/*.conf;
Example:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}

Important: If this directive already exists, you do not need to add it again.
Our DevOps and Cloud infrastructure experts can help you install, configure, and manage Nginx web servers, troubleshoot server configuration issues, set up virtual hosts, configure SSL certificates, and optimize web server performance. We also provide professional Linux server administration, Nginx migration, website deployment, server security, and cloud infrastructure management services.
Step 3: Create a Separate Virtual Host Configuration File
Create a configuration file for your domain inside the conf.d directory:
vi /etc/nginx/conf.d/example.com.conf
Add the following sample virtual host configuration:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
Save the file after updating the domain name and website document root.

Step 4: Test and Restart Nginx
Before restarting Nginx, verify that the configuration syntax is correct:
nginx -t
If the test is successful, reload the Nginx service:
systemctl reload nginx
You can also check the service status:
systemctl status nginx
Your virtual host configuration is now loaded directly from the conf.d directory without requiring symbolic links.

How to Verify the Nginx Virtual Host Configuration
After enabling your virtual host, you can verify that Nginx has loaded the configuration correctly.
Run:
nginx -T
This command displays the complete Nginx configuration, including the files loaded through the include directives.
You can also check the Nginx service status:
systemctl status nginx
To test your website locally, run:
curl -I http://example.com
Replace example.com with your actual domain name.
Make sure your domain DNS records point to the correct server IP address and that the required firewall ports are open.
Conclusion
The sites-available and sites-enabled directories are not created automatically in every Nginx installation, particularly on CentOS 7. This is because CentOS commonly follows a different Nginx configuration structure and uses the conf.d directory to manage virtual hosts.
If you prefer the Ubuntu-style configuration structure, you can manually create the missing directories and configure the appropriate include directive in nginx.conf. Alternatively, you can use the default conf.d directory to manage separate virtual host configuration files without creating symbolic links.
Both approaches work for managing multiple websites on an Nginx server. Choose the directory structure that best suits your server administration and configuration management requirements.
Frequently Asked Questions (FAQs)
1. Why is the sites-available directory missing in Nginx on CentOS 7?
The sites-available directory is not created by default in many CentOS 7 Nginx installations. Unlike Ubuntu and Debian, CentOS generally uses the /etc/nginx/conf.d/ directory to manage virtual host configuration files. You can manually create sites-available and sites-enabled directories and configure them in nginx.conf.
2. How do I enable sites-available and sites-enabled in Nginx?
Create both directories inside /etc/nginx/ and add the following directive inside the http block of /etc/nginx/nginx.conf:
include /etc/nginx/sites-enabled/*;
Create your virtual host configuration inside sites-available and use a symbolic link to enable it in sites-enabled. Then test and reload Nginx.
3. Can I configure Nginx virtual hosts without using sites-available and sites-enabled?
Yes. You can use the default /etc/nginx/conf.d/ directory instead. Create separate virtual host configuration files with a .conf extension, such as example.com.conf, and ensure that nginx.conf includes:
include /etc/nginx/conf.d/*.conf;
Test the configuration using nginx -t and reload Nginx to apply the changes.
Related Articles
How to Install Let’s Encrypt with Apache on CentOS 7
How to Block IPs via .htaccess File
Nginx Server Configuration and DevOps Support
Managing Nginx web servers, configuring virtual hosts, resolving server configuration errors, and maintaining reliable Linux infrastructure are essential for website availability and performance. At Pheonix Solutions, our DevOps experts help businesses configure Nginx servers, troubleshoot web server issues, manage virtual hosts, configure SSL certificates, and maintain secure cloud infrastructure.
We can help you with:
- DevOps and Cloud Services for Nginx server administration, virtual host configuration, Linux server management, SSL setup, server troubleshooting, and cloud infrastructure management.
- Website Development to build secure, responsive, and high-performing websites with reliable Nginx hosting and deployment environments.
- Software Maintenance and Support to troubleshoot website and server issues, maintain application environments, optimize web server performance, and ensure smooth operations.
Need help configuring Nginx virtual hosts, resolving missing configuration directories, setting up SSL certificates, or managing your Linux web server? Talk to our DevOps and Cloud experts to discuss your requirements.
