Managing multiple websites on a single Linux server becomes much easier with Nginx Server Blocks. This powerful Nginx feature allows administrators to host several domains on one server while maintaining separate configurations, document roots, logging, and security settings for each website.
Whether you’re running personal blogs, business websites, or development environments, server blocks provide a flexible and organized way to manage multiple domains on Ubuntu.
Nginx Server Blocks are configuration units that define how Nginx handles requests for specific domains or websites. They work similarly to Apache Virtual Hosts and enable one server to serve different websites based on the requested domain name.
Each server block can have:
This separation improves website management and simplifies troubleshooting.
Before configuring server blocks, ensure the following requirements are met:
Once these prerequisites are in place, you can begin creating individual website environments.
Each hosted website should have its own document root directory. A common approach is to organize websites under the /var/www directory.
Example structure:
/var/www/├── site1.com/│ └── public_html├── site2.com/│ └── public_html
Create a directory for your domain:
sudo mkdir -p /var/www/example.com/public_html
Next, create a simple HTML file to verify that the site loads correctly.
<!DOCTYPE html><html><head><title>Welcome</title></head><body><h1>Website Successfully Configured</h1></body></html>
After creating the files, assign ownership to the Nginx web server user:
sudo chown -R www-data:www-data /var/www/example.com
The configuration files for Nginx Server Blocks are typically stored in:
/etc/nginx/sites-available/
Create a new configuration file for your domain:
sudo nano /etc/nginx/sites-available/example.com
Add the basic configuration:
server { listen 80; server_name example.com www.example.com; root /var/www/example.com/public_html; index index.html; access_log /var/log/nginx/example.com.access.log; error_log /var/log/nginx/example.com.error.log;} This configuration instructs Nginx to serve files from the specified document root whenever requests arrive for the configured domain names.
To activate the configuration, create a symbolic link inside the enabled sites directory:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Before reloading Nginx, validate the syntax:
sudo nginx -t
If the test succeeds, restart the service:
sudo systemctl restart nginx
Now open your domain in a browser to verify that the website loads correctly.
Using server blocks offers several advantages:
For administrators managing multiple web properties, server blocks are an essential Nginx feature.
Nginx Server Blocks provide a reliable and scalable way to host multiple websites on a single Ubuntu server. By creating separate document roots and dedicated configurations for each domain, administrators gain better control, security, and flexibility. Once configured properly, Nginx Server Blocks make managing multi-site environments significantly easier while maintaining excellent performance.
OSINT is not just about tools. In 2026, the best open-source intelligence work depends on…
Building an OSINT lab does not have to be expensive. In 2026, many of the…
Website security is no longer optional. An Apache SSL Certificate helps encrypt data exchanged between…
Gradle has become one of the most widely used build automation tools in modern software…
Modern web applications often rely on caching to deliver faster response times and reduce database…
Install Jenkins Ubuntu systems quickly and efficiently to build powerful CI/CD pipelines for software development…