Updated: 18 November 2026 · Applies to: AlmaLinux 9 / Rocky Linux 9

CentOS 7 reached end of life on 30 June 2024, so this guide now uses AlmaLinux 9 / Rocky Linux 9 (the steps also suit other RHEL 9 rebuilds).

Server blocks (virtual hosts) let one Nginx server host several websites.

Steps

  1. Create a folder per site: mkdir -p /var/www/site1.com /var/www/site2.com.
  2. Create a configuration file per site in /etc/nginx/conf.d/ (AlmaLinux/Rocky) or /etc/nginx/sites-available/ plus a link in sites-enabled (Ubuntu/Debian):
    server {
        listen 80;
        server_name site1.com www.site1.com;
        root /var/www/site1.com;
        index index.html index.php;
        access_log /var/log/nginx/site1.access.log;
    }
  3. Test and reload: nginx -t && systemctl reload nginx.

Note: On AlmaLinux 9 / Rocky Linux 9 SELinux is on. Let Apache/Nginx write where the application needs it, for example: semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/site1.com/storage(/.*)?" && restorecon -R /var/www/site1.com, and allow outgoing connections if the app calls APIs: setsebool -P httpd_can_network_connect 1.

Add a free SSL certificate

apt install certbot python3-certbot-nginx                     # Ubuntu / Debian
dnf install epel-release && dnf install certbot python3-certbot-nginx   # AlmaLinux / Rocky
certbot --nginx -d example.com -d www.example.com

Certbot installs a timer that renews the certificate automatically; test it with certbot renew --dry-run.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket