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
Recall & Review
beginner
What is the purpose of the error_log directive in nginx?
The error_log directive tells nginx where to save error messages and what level of errors to record. It helps track problems in the server.
Click to reveal answer
beginner
How do you set the error log file path and error level in nginx?
Use error_log /path/to/logfile level; inside the nginx configuration. For example, error_log /var/log/nginx/error.log warn; saves warnings and above to that file.
Click to reveal answer
intermediate
Name four common error log levels in nginx.
The common levels are debug, info, notice, warn, error, and crit. They control how detailed the logs are.
Click to reveal answer
intermediate
Where can the error_log directive be placed in nginx configuration?
It can be placed in the main context (top level), http, server, or location blocks. More specific blocks override higher-level settings.
Click to reveal answer
advanced
What happens if you set the error log level to debug?
nginx logs very detailed information about its operations, which helps in deep troubleshooting but can create large log files and slow performance.
Click to reveal answer
Which directive sets the error log file in nginx?
Alog_format
Baccess_log
Cerror_log
Dserver_log
✗ Incorrect
The error_log directive configures where nginx writes error messages.
What is the default error log level if none is specified?
Aerror
Binfo
Cwarn
Ddebug
✗ Incorrect
If no level is set, nginx uses error level by default.
Where can you NOT place the error_log directive?
Aserver block
Binside a <code>if</code> statement
Clocation block
Dhttp block
✗ Incorrect
The error_log directive cannot be placed inside if statements.
Which error log level records the least amount of information?
Acrit
Bwarn
Cinfo
Ddebug
✗ Incorrect
crit logs only critical errors, so it records the least information.
What is a risk of setting error log level to debug in production?
ALogs may miss errors
BNo logs are created
CLogs become too small
DPerformance may slow and logs grow large
✗ Incorrect
Debug level creates very detailed logs, which can slow the server and fill disk space quickly.
Explain how to configure error logging in nginx including setting the log file and log level.
Think about the directive format and where it goes in the config.
You got /4 concepts.
Describe the impact of different error log levels on nginx logging and server performance.
Consider what happens when you log more or less information.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the error_log directive in nginx?
easy
A. To specify the file where error messages are recorded
B. To set the maximum number of client connections
C. To configure the server's IP address
D. To define the root directory for website files
Solution
Step 1: Understand the role of error logs
Error logs record problems and errors that happen in the server, helping to find and fix issues.
Step 2: Identify what error_log does
The error_log directive tells nginx where to save these error messages, specifying the file path and log level.
Final Answer:
To specify the file where error messages are recorded -> Option A
Quick Check:
error_log = file for errors [OK]
Hint: Error logs = where nginx saves error messages [OK]
Common Mistakes:
Confusing error_log with access_log
Thinking error_log sets server IP
Mixing error_log with client connection limits
2. Which of the following is the correct syntax to set the error log file to /var/log/nginx/error.log with log level warn?
easy
A. error_log /var/log/nginx/error.log level warn;
B. error_log = /var/log/nginx/error.log warn;
C. error_log /var/log/nginx/error.log warn
D. error_log /var/log/nginx/error.log warn;
Solution
Step 1: Recall nginx error_log syntax
The correct syntax is: error_log <file_path> <log_level>;
Step 2: Check each option
error_log /var/log/nginx/error.log warn; matches the correct syntax with semicolon and no extra symbols. Options A and B have invalid syntax, and D misses the semicolon.
Final Answer:
error_log /var/log/nginx/error.log warn; -> Option D
Quick Check:
Correct syntax ends with semicolon [OK]
Hint: Syntax: error_log path level; ends with semicolon [OK]
Common Mistakes:
Omitting the semicolon at the end
Using '=' sign incorrectly
Adding extra words like 'level'
3. Given this nginx configuration snippet:
error_log /var/log/nginx/error.log error;
What level of messages will be logged?
medium
A. Errors and more severe messages
B. Only critical errors
C. All messages including debug
D. Only warnings and errors
Solution
Step 1: Understand log levels hierarchy
Log levels in nginx from least to most severe: debug, info, notice, warn, error, crit, alert, emerg.
Step 2: Interpret 'error' level
Setting level to 'error' logs error and all more severe messages like critical, alert, emergency.
Final Answer:
Errors and more severe messages -> Option A
Quick Check:
error level logs error and above [OK]
Hint: Log level logs that level and higher severity [OK]
Common Mistakes:
Thinking it logs only critical errors
Assuming warnings are included at error level
Confusing debug with error level
4. You set error_log /var/log/nginx/error.log warn; but no warnings appear in the log file. What is the most likely cause?
medium
A. Error logs only record errors, not warnings
B. The log level 'warn' does not exist in nginx
C. The log file path is incorrect or not writable
D. You must restart nginx to enable error logging
Solution
Step 1: Check log file path and permissions
If the path is wrong or nginx cannot write to the file, logs won't appear.
Step 2: Validate log level and service status
'warn' is a valid level, and nginx logs warnings. Restarting is usually needed only after config changes, but logging works immediately if path is correct.
Final Answer:
The log file path is incorrect or not writable -> Option C
Quick Check:
Writable log file needed for logs [OK]
Hint: Check file path and permissions first if logs missing [OK]
Common Mistakes:
Assuming 'warn' is invalid log level
Forgetting to check file permissions
Thinking restart always needed for logging
5. You want to log all error messages including debug info to /var/log/nginx/full_error.log but keep normal error logs at /var/log/nginx/error.log with level error. Which configuration achieves this?
hard
A. error_log /var/log/nginx/error.log error debug;\nerror_log /var/log/nginx/full_error.log debug;
B. error_log /var/log/nginx/error.log error;\nerror_log /var/log/nginx/full_error.log debug;
C. error_log /var/log/nginx/error.log error;\nerror_log /var/log/nginx/full_error.log error;
D. error_log /var/log/nginx/error.log;\nerror_log /var/log/nginx/full_error.log debug;
Solution
Step 1: Understand multiple error_log directives
nginx allows multiple error_log directives to log to different files with different levels.
Step 2: Check each option for correct syntax and intent
error_log /var/log/nginx/error.log error;\nerror_log /var/log/nginx/full_error.log debug; correctly sets error level for normal log and debug level for full log. error_log /var/log/nginx/error.log error debug;\nerror_log /var/log/nginx/full_error.log debug; has invalid combined levels. error_log /var/log/nginx/error.log error;\nerror_log /var/log/nginx/full_error.log error; logs both at error level. error_log /var/log/nginx/error.log;\nerror_log /var/log/nginx/full_error.log debug; misses level for first log.
Final Answer:
error_log /var/log/nginx/error.log error;\nerror_log /var/log/nginx/full_error.log debug; -> Option B
Quick Check:
Separate directives for different levels [OK]
Hint: Use two error_log lines with different levels [OK]