Bird
Raised Fist0
Nginxdevops~10 mins

Separate config files per site in Nginx - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to include the site configuration file in nginx main config.

Nginx
include [1];
Drag options to blanks, or click blank then click option'
A/etc/nginx/conf.d/*.conf
B/etc/nginx/sites-available/*
C/usr/local/nginx/conf/*.conf
D/etc/nginx/sites-enabled/*
Attempts:
3 left
💡 Hint
Common Mistakes
Using sites-available instead of sites-enabled
Using conf.d which is for general configs
Using wrong directory paths
2fill in blank
medium

Complete the command to create a symbolic link for site1 config from sites-available to sites-enabled.

Nginx
ln -s [1] /etc/nginx/sites-enabled/site1.conf
Drag options to blanks, or click blank then click option'
A/usr/local/nginx/sites-available/site1.conf
B/etc/nginx/sites-enabled/site1.conf
C/etc/nginx/sites-available/site1.conf
D/etc/nginx/conf.d/site1.conf
Attempts:
3 left
💡 Hint
Common Mistakes
Linking from sites-enabled to sites-available
Using wrong source path
Confusing conf.d with sites-available
3fill in blank
hard

Fix the error in the server block to listen on port 80 for site2.

Nginx
server {
    listen [1];
    server_name site2.example.com;
    root /var/www/site2;
}
Drag options to blanks, or click blank then click option'
A8080
B80
C443 ssl
Dlocalhost
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 8080 which is non-standard
Using 443 without SSL config
Using 'localhost' which is invalid here
4fill in blank
hard

Fill both blanks to create a server block for site3 listening on port 443 with SSL enabled.

Nginx
server {
    listen [1] [2];
    server_name site3.example.com;
    root /var/www/site3;
}
Drag options to blanks, or click blank then click option'
A443
Bssl
C80
Dhttp2
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 80 for HTTPS
Omitting the ssl keyword
Using http2 without ssl
5fill in blank
hard

Fill all three blanks to create a location block that serves static files from /var/www/site4/static and disables logging.

Nginx
location [1] {
    root [2];
    access_log [3] off;
}
Drag options to blanks, or click blank then click option'
A/static
B/var/www/site4
Coff
D/var/www/site4/static
Attempts:
3 left
💡 Hint
Common Mistakes
Using full path in location instead of URL path
Setting root to static subfolder instead of base
Incorrect syntax for disabling access_log

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

  1. Step 1: Understand config file organization

    Separate config files help keep settings for each site distinct and clear.
  2. Step 2: Recognize management benefits

    This organization makes it easier to update or troubleshoot individual sites without affecting others.
  3. Final Answer:

    It keeps the nginx setup organized and easier to manage. -> Option D
  4. 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

  1. Step 1: Identify the correct directory for active sites

    The sites-enabled directory holds active site configs linked from sites-available.
  2. Step 2: Use the include directive properly

    Using include /etc/nginx/sites-enabled/*; loads all enabled site configs.
  3. Final Answer:

    include /etc/nginx/sites-enabled/*; -> Option C
  4. 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

  1. Step 1: Understand the ln -s command

    The command creates a symbolic link from the source to the target location.
  2. Step 2: Link sites-available to sites-enabled

    Linking example.com config into sites-enabled activates the site in nginx.
  3. Final Answer:

    It creates a symbolic link to enable example.com site. -> Option A
  4. 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

  1. Step 1: Understand sites-available vs sites-enabled

    Sites-available holds configs but only linked sites in sites-enabled are active.
  2. Step 2: Effect of missing link on reload

    Without a link, nginx ignores the new config and serves only enabled sites.
  3. Final Answer:

    The new site is ignored and not served. -> Option A
  4. 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

  1. Step 1: Enable site by linking config

    Create a symbolic link from sites-available/newsite to sites-enabled to activate it.
  2. Step 2: Test nginx config before reload

    Run nginx -t to check for syntax errors and avoid downtime.
  3. Step 3: Reload nginx to apply changes

    Use nginx -s reload to apply new config without stopping the server.
  4. Final Answer:

    Create symbolic link in sites-enabled, test config with nginx -t, then reload nginx -> Option B
  5. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard