0
0
Nginxdevops~20 mins

Why virtual hosting serves multiple domains in Nginx - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Virtual Hosting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does virtual hosting allow multiple domains on one server?

Imagine you have one apartment building but many tenants. How does virtual hosting in nginx let one server handle many websites (domains) like tenants in that building?

AIt uses the Host header in HTTP requests to serve the right website for each domain.
BIt requires a separate physical server for each domain.
CIt uses different IP addresses for each domain on the same server.
DIt changes the server's hostname dynamically for each request.
Attempts:
2 left
💡 Hint

Think about how a receptionist knows which tenant to call by reading the visitor's name on the request.

💻 Command Output
intermediate
2:00remaining
What is the output of nginx when virtual hosting is configured?

Given this nginx server block configuration snippet, what will nginx do when a request comes for example.com?

Nginx
server {
    listen 80;
    server_name example.com;
    root /var/www/example;
}
AServe files from /var/www/example for all domains regardless of Host header.
BServe files from /var/www/example when the Host header is example.com.
CReturn a 404 error for example.com requests.
DRedirect example.com requests to another server.
Attempts:
2 left
💡 Hint

Check how server_name matches the Host header.

Troubleshoot
advanced
3:00remaining
Why does nginx serve the wrong website for a domain?

You configured two server blocks for site1.com and site2.com. But when you visit site2.com, nginx shows site1.com content. What is the most likely cause?

Nginx
server {
    listen 80;
    server_name site1.com;
    root /var/www/site1;
}

server {
    listen 80;
    server_name site2.com;
    root /var/www/site2;
}
AThe DNS for site2.com points to a different server.
BThe root directory for site2.com is empty.
CThe server_name for site2.com is misspelled or missing.
DNginx does not support multiple server blocks on the same port.
Attempts:
2 left
💡 Hint

Check if nginx matches the Host header correctly.

🔀 Workflow
advanced
3:00remaining
Order the steps to add a new domain to nginx virtual hosting

Put these steps in the correct order to add a new domain mynewsite.com to an nginx server using virtual hosting.

A1,4,2,3
B2,1,4,3
C1,2,4,3
D4,1,2,3
Attempts:
2 left
💡 Hint

Think about preparing files before telling nginx about them.

Best Practice
expert
3:00remaining
Which practice ensures secure virtual hosting for multiple domains?

When hosting multiple domains on one nginx server, which practice best improves security and isolation?

AUse the same root directory for all domains to simplify management.
BRun nginx as root to allow access to all domain files.
CDisable SSL to avoid certificate conflicts between domains.
DUse separate user permissions and directories for each domain's files.
Attempts:
2 left
💡 Hint

Think about limiting damage if one site is compromised.