Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

NGINX - Customizing Logging to Fit Your Needs

Before we can start building our world-changing website or application on LEMP, we have to lay the foundation - the stack. In this hands-on lab, we will walk through customizing NGINX logging on Ubuntu Linux. We will explore configuring custom `access_log` and `error_log` locations, custom log formats and more. Completing this lab will provide a good understanding of how to customize logging in NGINX on Ubuntu Linux.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Aug 08, 2025
Duration
1h 0m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Configure the Logging Location for the Virtual Host

    Become the root user:

    sudo su -
    

    Edit the bigstatecollege.edu.conf file:

    cd /etc/nginx/sites-available
    
    vi bigstatecollege.edu.conf
    

    After the server_name line, add the following:

            access_log /var/log/nginx/bigstatecollege.edu_access.log;
            error_log /var/log/nginx/bigstatecollege.edu_error.log;
    

    Save and exit.

  2. Challenge

    Test the New Logging Location for the Virtual Host

    Validate / reload NGINX:

    nginx -t
    
    systemctl reload nginx
    

    Test the new configuration:

    curl --insecure https://www.bigstatecollege.edu
    
    ls -al /var/log/nginx/
    

    We should see the new logs. Take a look at the contents of the new access log:

    cat /var/log/nginx/bigstatecollege.edu_access.log
    

    Access the virtual host several more times. Access a file that doesn't exist, then take a look at the contents of the log again.

  3. Challenge

    Configure the Error Logging Level for the Virtual Host

    We're going to set the error logs to the debug level, the most verbose:

    vi bigstatecollege.edu.conf
    

    On the error_log line, add debug:

    error_log /var/log/nginx/bigstatecollege.edu_error.log debug;
    

    Save and exit.

  4. Challenge

    Test the Error Logging Level for the Virtual Host

    Validate / reload NGINX:

    nginx -t
    
    systemctl reload nginx
    

    Test the new configuration:

    curl --insecure https://www.bigstatecollege.edu
    
    curl --insecure https://www.bigstatecollege.edu/foo.txt
    

    Let's see what we generated in the new error log:

    cat /var/log/nginx/bigstatecollege.edu_error.log
    

    We'll see there's more detail in there.

  5. Challenge

    Configure the Access Log to Use the 'custom' Format

    Edit the virtual host configuration file:

    vi bigstatecollege.edu.conf
    

    On the access_log line, add the following:

    access_log /var/log/nginx/bigstatecollege.edu_access.log custom;
    

    Save and exit.

    We will need to define the custom logging level in the nginx.conf file:

    vi ../nginx.conf
    
  6. Challenge

    Configure the 'custom' Access Log Format in nginx.conf

    After the error_log line, add the following:

    log_format  custom '$remote_addr - $remote_user [$time_local] '
                                 '"$request" $status $body_bytes_sent '
                                 '"$http_referer" "$http_user_agent" '
                                 '"$http_x_forwarded_for" $request_id '
                                 '$geoip_country_name $geoip_country_code '
                                 '$geoip_region_name $geoip_city ';
    

    Save and exit.

  7. Challenge

    Test the 'custom' Access Log Format

    Validate and reload NGINX:

    nginx -t
    
    systemctl reload nginx
    

    Let's test the new configuration:

    curl --insecure https://www.bigstatecollege.edu
    
    curl --insecure https://www.bigstatecollege.edu/foo.txt
    

    Now, let's see what we generated in the new access log:

    cat /var/log/nginx/bigstatecollege.edu_access.log
    

    You'll see the format of the access log has changed.

About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight