Beginner Fundamentals
Virtual Hosts
A single Nginx server can host many websites at once. Each site gets its own server block, a setup commonly called virtual hosting.
Multiple Server Blocks
server {
listen 80;
server_name site-one.com;
root /var/www/site-one;
}
server {
listen 80;
server_name site-two.com;
root /var/www/site-two;
}
Both listen on port 80. Nginx routes each request to the matching block based on the Host header.
The sites-available Pattern
On Debian and Ubuntu, configs are organized into two folders:
/etc/nginx/sites-available/holds one file per site./etc/nginx/sites-enabled/holds symlinks to the active sites.
The main nginx.conf includes the enabled folder:
include /etc/nginx/sites-enabled/*;
Enabling a Site
Create the config in sites-available, then link it:
sudo ln -s /etc/nginx/sites-available/site-one /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Disabling a Site
Remove the symlink, not the original file, then reload:
sudo rm /etc/nginx/sites-enabled/site-one
sudo systemctl reload nginx
This pattern keeps every site’s config available while letting you turn sites on and off without deleting anything.