>_ IzzyLab

Hands-on task

This task is step 2 of the course “nginx basics”

Custom 404 Page

medium~15 min

Configure nginx (port 80): when a non-existent path is requested, it must return its own error page with the text Page not found and status 404.

What you'll practise:
  • nginx
  • error_page
  • location
  • docroot
  • http statuses

Topic breakdown

nginx lets you replace standard error pages with your own via the error_page directive, which ties a response code to an internal resource. The page file itself is placed in the site root (docroot), and access to it is restricted with a separate location using an exact match and the internal marker — so the page is served only as a response to an error, not by a direct request. Important to understand: replacing the body doesn't change the HTTP status — the client still receives the original error code. After editing, the config is checked (nginx -t) and reread without stopping the server.

What's checked

  1. non-existent path returns 404
  2. the custom "Page not found" page is served
  3. the home page is still served

What it looks like