Bird
Raised Fist0
Nginxdevops~20 mins

Configuration testing (nginx -t) - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Nginx Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of nginx -t with a valid configuration?
You run nginx -t after editing the configuration file and it is valid. What output do you expect?
A
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
B
nginx: [emerg] unknown directive "bad_directive" in /etc/nginx/nginx.conf:10
nginx: configuration file /etc/nginx/nginx.conf test failed
C
nginx: [warn] deprecated syntax in /etc/nginx/nginx.conf:5
nginx: configuration file /etc/nginx/nginx.conf test failed
Dbash: nginx: command not found
Attempts:
2 left
💡 Hint
Think about what nginx -t reports when the config is correct.
💻 Command Output
intermediate
2:00remaining
What error does nginx -t show for a missing semicolon?
You forgot a semicolon at the end of a directive in /etc/nginx/nginx.conf. What error message will nginx -t display?
A
nginx: [error] invalid directive in /etc/nginx/nginx.conf:15
nginx: configuration file /etc/nginx/nginx.conf test failed
B
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/nginx.conf:15
nginx: configuration file /etc/nginx/nginx.conf test failed
C
nginx: configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
D
nginx: [warn] missing semicolon in /etc/nginx/nginx.conf:15
nginx: configuration file /etc/nginx/nginx.conf test is successful
Attempts:
2 left
💡 Hint
Look for an error mentioning missing semicolon or unexpected end of file.
Troubleshoot
advanced
2:30remaining
Why does nginx -t fail with 'unknown directive' error?
You added a new directive bad_directive in your nginx config and ran nginx -t. It failed with an 'unknown directive' error. What is the most likely cause?
AThe directive name is misspelled or not supported by the installed nginx version.
BThe server block is missing a closing brace.
CThe configuration file has incorrect file permissions.
DThe nginx service is not running, so the test cannot complete.
Attempts:
2 left
💡 Hint
Think about what 'unknown directive' means in nginx config context.
Best Practice
advanced
2:00remaining
What is the best practice before reloading nginx after config changes?
You edited the nginx configuration file. What should you do before running systemctl reload nginx to avoid downtime?
ADelete the old configuration file to avoid conflicts.
BRestart the server to apply changes safely.
CRun <code>nginx -t</code> to test the configuration syntax for errors.
DRun <code>systemctl stop nginx</code> before reloading.
Attempts:
2 left
💡 Hint
Think about how to check config correctness without stopping the service.
🔀 Workflow
expert
3:00remaining
Order the steps to safely update nginx configuration with zero downtime
Arrange the following steps in the correct order to update nginx configuration safely without downtime.
A1,2,4,3
B2,1,3,4
C1,3,2,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Remember to test config before reloading, and verify service after reload.

Practice

(1/5)
1. What is the primary purpose of running nginx -t before restarting the nginx service?
easy
A. To check the nginx configuration syntax for errors without applying changes
B. To restart the nginx service immediately
C. To display the current nginx server status
D. To update nginx to the latest version

Solution

  1. Step 1: Understand the command purpose

    The nginx -t command tests the configuration files for syntax errors without starting or restarting the server.
  2. Step 2: Differentiate from other commands

    Restarting or checking status uses different commands like systemctl restart nginx or systemctl status nginx. Updating nginx is unrelated.
  3. Final Answer:

    To check the nginx configuration syntax for errors without applying changes -> Option A
  4. Quick Check:

    nginx -t = syntax check [OK]
Hint: Use nginx -t to verify config syntax before restart [OK]
Common Mistakes:
  • Confusing nginx -t with restart command
  • Thinking nginx -t applies changes
  • Using nginx -t to check server status
2. Which of the following is the correct syntax to test nginx configuration files?
easy
A. nginx --test
B. nginx test-config
C. nginx -t
D. nginx --check

Solution

  1. Step 1: Recall nginx test command syntax

    The correct command to test nginx configuration syntax is nginx -t.
  2. Step 2: Verify other options

    Options like --test, test-config, or --check are invalid and will cause errors.
  3. Final Answer:

    nginx -t -> Option C
  4. Quick Check:

    Correct test syntax = nginx -t [OK]
Hint: Remember short flag -t for testing config syntax [OK]
Common Mistakes:
  • Using long or incorrect flags like --test
  • Typing commands that don't exist
  • Confusing test with restart commands
3. You run sudo nginx -t and see the output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

What does this output mean?
medium
A. The nginx configuration has syntax errors and cannot start
B. The nginx service has restarted successfully
C. The nginx configuration file is missing
D. The nginx configuration syntax is correct and ready to reload

Solution

  1. Step 1: Interpret the output messages

    The output states the syntax is ok and the test is successful, meaning no errors were found in the config files.
  2. Step 2: Understand what the test implies

    This means nginx can safely reload or restart using this configuration without syntax issues.
  3. Final Answer:

    The nginx configuration syntax is correct and ready to reload -> Option D
  4. Quick Check:

    Syntax ok + test successful = config valid [OK]
Hint: Look for 'syntax is ok' and 'test is successful' in output [OK]
Common Mistakes:
  • Assuming test means service restarted
  • Confusing syntax errors with warnings
  • Ignoring the success message
4. You run sudo nginx -t and get this error:
nginx: [emerg] unknown directive "servere" in /etc/nginx/nginx.conf:12
nginx: configuration file /etc/nginx/nginx.conf test failed

What is the best way to fix this?
medium
A. Correct the typo "servere" to "server" in the config file
B. Ignore the error and restart nginx anyway
C. Delete the entire nginx.conf file
D. Run nginx -s reload without changes

Solution

  1. Step 1: Identify the error cause

    The error shows an unknown directive "servere" at line 12, which is likely a typo for "server".
  2. Step 2: Fix the configuration file

    Editing the config file to correct the typo will fix the syntax error and allow nginx to test successfully.
  3. Final Answer:

    Correct the typo "servere" to "server" in the config file -> Option A
  4. Quick Check:

    Fix typos in config to pass nginx -t test [OK]
Hint: Fix typos in config file before restarting nginx [OK]
Common Mistakes:
  • Restarting nginx without fixing errors
  • Deleting config files unnecessarily
  • Ignoring error messages
5. You have multiple nginx config files included in /etc/nginx/nginx.conf. After editing one included file, which command sequence ensures safe application of changes?
hard
A. Run nginx -s stop then nginx -s start without testing
B. Run nginx -t to test, then sudo systemctl reload nginx if no errors
C. Delete the edited file and restart nginx
D. Directly run sudo systemctl restart nginx without testing

Solution

  1. Step 1: Test all config files including included ones

    Running nginx -t checks syntax across main and included config files to catch errors before reload.
  2. Step 2: Reload nginx safely if test passes

    If the test is successful, use sudo systemctl reload nginx to apply changes without downtime.
  3. Final Answer:

    Run nginx -t to test, then sudo systemctl reload nginx if no errors -> Option B
  4. Quick Check:

    Test config then reload nginx safely [OK]
Hint: Always test config before reload to avoid downtime [OK]
Common Mistakes:
  • Restarting without testing config
  • Stopping nginx instead of reloading
  • Ignoring included config files