0
0
Nginxdevops~20 mins

Why virtual hosting serves multiple domains in Nginx - See It in Action

Choose your learning style9 modes available
Why Virtual Hosting Serves Multiple Domains in Nginx
📖 Scenario: You are setting up a web server that needs to serve two different websites using the same server. This is common when you want to host multiple domains without buying separate servers for each.
🎯 Goal: Learn how to configure Nginx virtual hosting to serve multiple domains from one server.
📋 What You'll Learn
Create two server blocks for two different domains
Set the root directory for each domain
Configure server_name for each domain
Test that each domain serves the correct content
💡 Why This Matters
🌍 Real World
Web hosting companies use virtual hosting to serve many customers on one server.
💼 Career
Understanding virtual hosting is essential for system administrators and DevOps engineers managing web servers.
Progress0 / 4 steps
1
Create the first server block for example1.com
Create a server block in Nginx configuration with server_name example1.com; and set the root to /var/www/example1.
Nginx
Need a hint?

Use server_name to specify the domain and root to specify the folder with website files.

2
Add the second server block for example2.com
Add another server block with server_name example2.com; and set the root to /var/www/example2 below the first server block.
Nginx
Need a hint?

Each domain needs its own server block with its own server_name and root.

3
Explain why virtual hosting works for multiple domains
Add a comment above the server blocks explaining that Nginx uses server_name to decide which block serves a request for a domain.
Nginx
Need a hint?

Write a simple comment starting with # explaining the role of server_name.

4
Display the final Nginx configuration
Print the full Nginx configuration showing both server blocks and the comment.
Nginx
Need a hint?

Just show the full configuration text as output.