Virtual hosting allows a single web server to host multiple domain names or websites on the same IP address.
Click to reveal answer
beginner
Why do we use virtual hosting to serve multiple domains?
To save resources by using one server and IP address to handle many websites, making hosting efficient and cost-effective.
Click to reveal answer
intermediate
How does nginx know which website to serve when multiple domains use virtual hosting?
Nginx uses the 'server_name' directive to match the requested domain and serve the correct website content.
Click to reveal answer
intermediate
What is the difference between IP-based and name-based virtual hosting?
IP-based uses different IP addresses for each domain; name-based uses the same IP but distinguishes domains by their names.
Click to reveal answer
beginner
How does virtual hosting relate to real-life apartment buildings?
Like one building with many apartments, virtual hosting lets one server host many websites, each with its own address (domain).
Click to reveal answer
What directive does nginx use to serve different websites on the same server?
Aserver_name
Blisten_port
Croot_path
Dproxy_pass
✗ Incorrect
The 'server_name' directive tells nginx which domain name to respond to for each website.
Why is virtual hosting useful?
AIt blocks unwanted domains.
BIt allows hosting multiple domains on one server and IP address.
CIt increases the server's IP addresses.
DIt speeds up internet connection.
✗ Incorrect
Virtual hosting lets one server handle many domains, saving resources and costs.
Which type of virtual hosting uses the same IP address for multiple domains?
APort-based virtual hosting
BIP-based virtual hosting
CName-based virtual hosting
DDNS-based virtual hosting
✗ Incorrect
Name-based virtual hosting uses one IP address and distinguishes domains by their names.
If two domains share one IP address, how does nginx serve the correct site?
ABy checking the domain name in the request header
BBy using different ports
CBy changing IP addresses dynamically
DBy using different server hardware
✗ Incorrect
Nginx reads the domain name sent by the browser to decide which site to serve.
What is a real-life example similar to virtual hosting?
AOne car with many engines
BOne book with many covers
COne phone number for many people
DOne apartment building with many apartments
✗ Incorrect
An apartment building hosts many apartments at one address, like one server hosting many domains.
Explain how virtual hosting allows one server to serve multiple websites.
Think about how nginx uses domain names to decide which website to show.
You got /4 concepts.
Describe the difference between IP-based and name-based virtual hosting.
Consider how the server identifies the website to serve.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of virtual hosting in nginx?
easy
A. To create backups of website data automatically
B. To increase the server's CPU speed
C. To block unwanted visitors from accessing the server
D. To serve multiple websites from a single server using different domain names
Solution
Step 1: Understand virtual hosting concept
Virtual hosting allows one server to handle many websites by using domain names to select content.
Step 2: Identify the main purpose
This means the server can serve different websites without needing separate servers for each domain.
Final Answer:
To serve multiple websites from a single server using different domain names -> Option D
Quick Check:
Virtual hosting = multiple domains on one server [OK]
Hint: Virtual hosting means many sites, one server [OK]
Common Mistakes:
Thinking virtual hosting speeds up CPU
Confusing virtual hosting with backups
Believing it blocks visitors
2. Which nginx directive is used to specify the domain names for virtual hosting?
easy
A. server_name
B. location
C. listen
D. root
Solution
Step 1: Recall nginx configuration directives
The server_name directive tells nginx which domain names a server block should respond to.
Step 2: Match directive to purpose
Other directives like root set content folder, listen sets port, location defines URL paths.
Final Answer:
server_name -> Option A
Quick Check:
Domain names use server_name [OK]
Hint: Domain names go in server_name directive [OK]
Common Mistakes:
Using root for domain names
Confusing listen with domain matching
Thinking location sets domain
3. Given this nginx server block snippet, what domain will it serve?
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example;
}
medium
A. Only example.com
B. Only www.example.com
C. Both example.com and www.example.com
D. Any domain on port 80
Solution
Step 1: Read server_name directive
The server_name lists both example.com and www.example.com, so nginx matches requests for either domain.
Step 2: Understand nginx matching
Requests to either domain on port 80 will serve content from /var/www/example.
Final Answer:
Both example.com and www.example.com -> Option C
Quick Check:
server_name lists multiple domains = serve all listed [OK]
Hint: server_name can list many domains separated by spaces [OK]
Common Mistakes:
Assuming only first domain is served
Thinking root defines domain
Believing nginx serves all domains by default
4. You configured two server blocks with the same server_name but different root paths. What will happen when a request comes for that domain?
medium
A. nginx will merge both roots and serve combined content
B. nginx will serve content from the first server block it finds
C. nginx will return an error about duplicate server_name
D. nginx will randomly choose one root each time
Solution
Step 1: Understand nginx server block matching
When multiple server blocks have the same server_name, nginx uses the first matching block it finds in the config.
Step 2: Result of duplicate server_name
It does not merge roots or error out; it simply picks the first block, so only one root is used.
Final Answer:
nginx will serve content from the first server block it finds -> Option B
Quick Check:
Duplicate server_name = first block wins [OK]
Hint: Duplicate server_name uses first matching block [OK]
Common Mistakes:
Expecting nginx to merge content folders
Thinking nginx throws error on duplicates
Assuming random selection
5. You want to serve two domains, site1.com and site2.com, on the same nginx server. Which configuration correctly uses virtual hosting to serve different content for each domain?
hard
A. server { listen 80; server_name site1.com; root /var/www/site1; } server { listen 80; server_name site2.com; root /var/www/site2; }
B. server { listen 80; server_name site1.com site2.com; root /var/www/site1; }
C. server { listen 80; server_name site1.com; root /var/www/site1; } server { listen 80; server_name site1.com; root /var/www/site2; }
D. server { listen 80; root /var/www/site1; } server { listen 80; root /var/www/site2; }
Solution
Step 1: Check domain to root mapping
server { listen 80; server_name site1.com; root /var/www/site1; } server { listen 80; server_name site2.com; root /var/www/site2; } uses two server blocks, each with a unique server_name and root folder, correctly separating content by domain.
Step 2: Analyze other options
server { listen 80; server_name site1.com site2.com; root /var/www/site1; } serves both domains from one root, so content is not separated. server { listen 80; server_name site1.com; root /var/www/site1; } server { listen 80; server_name site1.com; root /var/www/site2; } duplicates server_name causing conflict. server { listen 80; root /var/www/site1; } server { listen 80; root /var/www/site2; } lacks server_name, so domains won't be matched properly.
Final Answer:
Two server blocks with distinct server_name and root for each domain -> Option A
Quick Check:
Separate server blocks = separate domains and content [OK]
Hint: Use separate server blocks for each domain with server_name [OK]
Common Mistakes:
Putting multiple domains in one block with one root
Duplicating server_name in multiple blocks
Omitting server_name directive
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.