0
0
Nginxdevops~30 mins

Log format customization in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Log Format Customization in Nginx
📖 Scenario: You are managing a web server using Nginx. You want to customize the log format to include specific details about each request for better monitoring and troubleshooting.
🎯 Goal: Learn how to create a custom log format in Nginx and apply it to the access logs.
📋 What You'll Learn
Create a custom log format named custom_format with specific fields
Set a variable for the log file path
Apply the custom log format to the access log directive
Print the final access log configuration line
💡 Why This Matters
🌍 Real World
Customizing log formats helps system administrators and DevOps engineers monitor web traffic and troubleshoot issues effectively by capturing exactly the information they need.
💼 Career
Understanding how to customize and manage Nginx logs is a key skill for roles like DevOps engineer, system administrator, and site reliability engineer.
Progress0 / 4 steps
1
Create a custom log format
Write a log_format directive named custom_format that logs the client IP ($remote_addr), the request time ($time_local), the request method ($request_method), the requested URI ($request_uri), the response status ($status), and the body bytes sent ($body_bytes_sent).
Nginx
Need a hint?

Use the log_format directive with the name custom_format and include the variables exactly as shown.

2
Set the access log file path variable
Create a variable called access_log_path and set it to the string "/var/log/nginx/access_custom.log".
Nginx
Need a hint?

Use the set directive to assign the log file path to the variable $access_log_path.

3
Apply the custom log format to the access log
Write an access_log directive that uses the variable $access_log_path as the log file path and the custom_format as the log format.
Nginx
Need a hint?

Use the access_log directive with the variable $access_log_path and the format name custom_format.

4
Display the final access log configuration
Write a print statement that outputs the exact string: access_log /var/log/nginx/access_custom.log custom_format;
Nginx
Need a hint?

Use print with the exact string including the semicolon.