§2023-04-06


3.2.3.1 Managing server entries

It is possible to put different server blocks in different files. This allows you to easily enable or disable certain sites.

Create the following directories:

# mkdir /etc/nginx/sites-available
# mkdir /etc/nginx/sites-enabled

Create a file inside the sites-available directory that contains one or more server blocks:

/etc/nginx/sites-available/example.conf
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ...
}

Append include sites-enabled/*; to the end of the http block:

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

To enable a site, simply create a symlink:

# ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/example.conf

To disable a site, unlink the active symlink:

# unlink /etc/nginx/sites-enabled/example.conf

Reload/restart nginx.service to enable changes to the sites configuration.