Why use separate config files for each site in nginx?
Using separate config files helps organize settings, makes it easier to manage multiple sites, and allows enabling or disabling sites without affecting others.
Click to reveal answer
beginner
Where are separate site config files usually stored in nginx?
They are typically stored in the /etc/nginx/sites-available/ directory, with symbolic links in /etc/nginx/sites-enabled/ to activate them.
Click to reveal answer
intermediate
What command activates a site config in nginx when using separate files?
You create a symbolic link from /etc/nginx/sites-available/your-site to /etc/nginx/sites-enabled/your-site using ln -s /etc/nginx/sites-available/your-site /etc/nginx/sites-enabled/your-site.
Click to reveal answer
beginner
How do you reload nginx after adding or changing a site config file?
Run sudo nginx -t to test the config, then sudo systemctl reload nginx to apply changes without downtime.
Click to reveal answer
intermediate
What is the purpose of the include directive in nginx main config for separate site files?
It tells nginx to load all site config files from a directory, usually include /etc/nginx/sites-enabled/*;, so each site config is read automatically.
Click to reveal answer
Where should you place individual site config files in nginx?
A/etc/nginx/sites-available/
B/var/www/html/
C/usr/local/nginx/conf/
D/etc/nginx/conf.d/
✗ Incorrect
Site config files are placed in /etc/nginx/sites-available/ for organization and management.
How do you enable a site config in nginx after creating it in sites-available?
ACopy it to /etc/nginx/sites-enabled/
BEdit /etc/nginx/nginx.conf directly
CCreate a symbolic link in /etc/nginx/sites-enabled/
DRestart the server without changes
✗ Incorrect
Creating a symbolic link in sites-enabled activates the site config.
What command checks nginx config syntax before reloading?
Anginx -t
Bnginx -c
Cnginx -s reload
Dsystemctl status nginx
✗ Incorrect
The command nginx -t tests the configuration syntax.
What does the include directive do in nginx config?
ACreates symbolic links
BStarts the nginx server
CDisables site configs
DIncludes external files into the main config
✗ Incorrect
The include directive loads other config files into nginx's main configuration.
Why is it better to use separate config files per site?
ATo reduce server memory
BTo organize and manage sites easily
CTo speed up nginx startup
DTo avoid using symbolic links
✗ Incorrect
Separate files help keep site configs organized and easy to manage.
Explain how to set up nginx to serve multiple websites using separate config files.
Think about file locations, linking, and commands to reload.
You got /5 concepts.
Describe the benefits of using separate config files per site in nginx.
Consider how managing many sites is easier this way.
You got /5 concepts.
Practice
(1/5)
1. What is the main benefit of using separate config files per site in nginx?
easy
A. It makes nginx run faster by loading fewer files.
B. It allows nginx to serve only one site at a time.
C. It automatically secures each site with HTTPS.
D. It keeps the nginx setup organized and easier to manage.
Solution
Step 1: Understand config file organization
Separate config files help keep settings for each site distinct and clear.
Step 2: Recognize management benefits
This organization makes it easier to update or troubleshoot individual sites without affecting others.
Final Answer:
It keeps the nginx setup organized and easier to manage. -> Option D
Quick Check:
Separate configs = better organization [OK]
Hint: Separate files mean easier site management [OK]
Common Mistakes:
Thinking separate files speed up nginx
Assuming separate files enable HTTPS automatically
Believing nginx serves only one site with separate files
2. Which nginx directive correctly includes all site config files from the sites-enabled directory?
easy
A. include /etc/nginx/conf.d/*;
B. include /etc/nginx/sites-available/*;
C. include /etc/nginx/sites-enabled/*;
D. include /etc/nginx/sites-enabled.conf;
Solution
Step 1: Identify the correct directory for active sites
The sites-enabled directory holds active site configs linked from sites-available.
Step 2: Use the include directive properly
Using include /etc/nginx/sites-enabled/*; loads all enabled site configs.
Final Answer:
include /etc/nginx/sites-enabled/*; -> Option C
Quick Check:
Include sites-enabled/* loads active sites [OK]
Hint: Include sites-enabled/* to load active sites [OK]
Common Mistakes:
Including sites-available instead of sites-enabled
Using wrong directory like conf.d for site configs
Missing the wildcard * to include all files
3. Given the command ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/, what is the effect?
medium
A. It creates a symbolic link to enable example.com site.
B. It copies the example.com config to sites-enabled.
C. It deletes the example.com config file.
D. It disables the example.com site.
Solution
Step 1: Understand the ln -s command
The command creates a symbolic link from the source to the target location.
Step 2: Link sites-available to sites-enabled
Linking example.com config into sites-enabled activates the site in nginx.
Final Answer:
It creates a symbolic link to enable example.com site. -> Option A
Quick Check:
ln -s from sites-available to sites-enabled enables site [OK]
Hint: ln -s link enables site by linking config [OK]
Common Mistakes:
Thinking ln -s disables the site
Assuming ln -s deletes or copies files
Confusing symbolic link with file copy
4. You added a new site config in sites-available but forgot to link it in sites-enabled. What happens when you reload nginx?
medium
A. The new site is ignored and not served.
B. Nginx throws a syntax error and fails to reload.
C. The new site is active and served by nginx.
D. Nginx deletes the config file automatically.
Solution
Step 1: Understand sites-available vs sites-enabled
Sites-available holds configs but only linked sites in sites-enabled are active.
Step 2: Effect of missing link on reload
Without a link, nginx ignores the new config and serves only enabled sites.
Final Answer:
The new site is ignored and not served. -> Option A
Quick Check:
Missing link means site ignored on reload [OK]
Hint: Link site config to sites-enabled to activate [OK]
Common Mistakes:
Expecting nginx to auto-enable new configs
Thinking nginx reload fails without link
Assuming nginx deletes unlinked configs
5. You want to add a new site with config in /etc/nginx/sites-available/newsite. Which sequence correctly enables it and reloads nginx safely?
hard
A. Copy config to sites-enabled, then run nginx -s reload
B. Create symbolic link in sites-enabled, test config with nginx -t, then reload nginx
C. Edit nginx.conf directly to add newsite, then restart nginx
D. Move config to sites-enabled, then reload nginx without testing
Solution
Step 1: Enable site by linking config
Create a symbolic link from sites-available/newsite to sites-enabled to activate it.
Step 2: Test nginx config before reload
Run nginx -t to check for syntax errors and avoid downtime.
Step 3: Reload nginx to apply changes
Use nginx -s reload to apply new config without stopping the server.
Final Answer:
Create symbolic link in sites-enabled, test config with nginx -t, then reload nginx -> Option B
Quick Check:
Link + test + reload = safe enable [OK]
Hint: Always test config before reload after linking site [OK]
Common Mistakes:
Copying instead of linking config files
Reloading nginx without testing config
Editing nginx.conf instead of using sites-available
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.