Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
VGSOURCES
Get listed

404 errorsPATCH 2026.10.15

How to Create Custom Nginx Error Pages (404 and More)

By VGSources Team 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a static HTML file inside the active Nginx document root, map the relevant status with error_page, optionally protect the error location with internal, then validate and reload Nginx. The same pattern handles branded 404 pages, shared 5xx fallbacks, application handlers, and deliberate redirects.

What a custom Nginx error page does

Nginx normally generates a minimal response when it cannot find a resource or an upstream request fails. The error_page directive replaces that response body, routes processing to another handler, or redirects the browser. It can be declared in http, server, location, or if inside a location. The directive’s basic form is error_page code ... [=[response]] uri;.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A local error page is an internal redirect: Nginx processes the target URI without asking the browser to make a new request. For methods other than GET and HEAD, that internal redirect changes the method to GET. The browser therefore keeps its original URL while receiving a purpose-built document.

The target still has to resolve like any other local file. Nginx appends the request URI to the configured root path. If the target file is outside that root, misspelled, unreadable, or hidden by a more specific location, the error handling request can produce another 404.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses | Anti UV Ray, For Computers & Gaming, Square Frame, Eyewear for Men and Women
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Build a basic local 404 page

1. Create the HTML document under the active root

Suppose the server block uses /var/www/example as its document root. Create /var/www/example/404.html with a short, useful response. This example gives visitors a navigation link without exposing server details:

<!doctype html>
<html lang='en'>
<head>
  <meta charset='utf-8'>
  <meta name='viewport' content='width=device-width, initial-scale=1'>
  <title>Page not found</title>
</head>
<body>
  <main>
    <h1>Page not found</h1>
    <p>The address may be outdated or the page may have moved.</p>
    <p><a href='/'>Return to the home page</a></p>
  </main>
</body>
</html>

Keep the document static unless you have a specific reason to run an application for errors. Do not put passwords, tokens, stack traces, upstream hostnames, deployment paths, or other internal data in the page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Map status 404 to that file

Add the mapping to the server block that serves the request:

server {
    root /var/www/example;

    error_page 404 /404.html;

    location = /404.html {
        internal;
    }
}

With this configuration, a missing resource receives the custom document while retaining a 404 response. The exact-match location applies only to /404.html, and internal prevents visitors from fetching that URI directly.

3. Understand the root calculation

For a request such as /images/missing.png, Nginx combines the URI with the root and checks /var/www/example/images/missing.png. For the error mapping above, it checks /var/www/example/404.html. Confirm the file is in that directory, that the Nginx worker can read it, and that the active virtual host really uses this root.

4. Test a URL that should not exist

Request a deliberately missing path, not /404.html itself. Because the location is marked internal, a direct request to /404.html is expected to return 404. That behavior is intentional; it does not mean the internal error mapping failed.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use one page for several status codes

When the same fallback design is appropriate for several server failures, list the status codes before one URI. Nginx’s documented grouped form is:

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

The first rule serves the not-found page. The second uses one static page for an application error, a bad gateway response, temporary unavailability, and a gateway timeout. Create /var/www/example/50x.html under the same root and protect it in the same way:

location = /50x.html {
    internal;
}

Grouping is a presentation decision, not a claim that all failures have the same cause. Your 50x text can say that the service is temporarily unavailable and provide a support route without revealing whether the failure was a timeout or an upstream crash.

Make missing-file behavior explicit with try_files

For a static site or a front controller, try_files determines which filesystem paths are attempted before Nginx returns an error. A common explicit fallback is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
location / {
    try_files $uri $uri/ $uri.html =404;
}

Nginx checks the requested file, then a directory, then a filename with .html appended. If none exists, =404 selects the 404 status. The error_page 404 /404.html; rule can then supply the branded body. This arrangement separates two jobs: try_files decides whether a resource exists, while error_page decides how the resulting status is presented.

Check the order carefully. A broad location / can be overridden by a more specific location, and a nested location with its own error handling may not use the server-level rule you expected.

Choose the right error-page target

These forms differ in status handling, browser-visible URL, and request method:

Option Keeps original status? Changes URL? Changes method? Typical use
error_page 404 /404.html; Yes, unless overridden No Non-GET/HEAD becomes GET during the internal redirect Branded static 404 or 50x page
error_page 404 = /handler; The selected handler or upstream can determine it No Internal redirect rules apply Explicit status control or an application handler
error_page 404 = @fallback; The named location or backend decides No URI and method are preserved for error processing Proxy or application fallback
error_page 404 http://example.com/notfound; No; the browser receives a redirect status Yes The browser follows the redirect Legacy URL migration or a centralized error site

Use a local URI when the error should look native to the current site. Use a named location when preserving request information is more important than serving a static file. Use an external redirect only when changing the browser’s destination is deliberate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men | Office Gifts for Women, iPhone Stand, Gadgets for Men, Office Decor, Gaming Desk Accessories for Samsung Fold 8, Switch, iPad
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Preserve the request with a named location

Internal redirection to a URI changes non-GET and non-HEAD methods to GET. If an error must be handed to a proxy while preserving the original URI and method, route it to a named location:

location / {
    error_page 404 = @fallback;
}

location @fallback {
    proxy_pass http://backend;
}

The @fallback target is not a public URI and is selected inside Nginx’s configuration. The equals sign tells Nginx to use the named location’s result rather than automatically forcing the original 404 response. The backend can generate the body and choose the final status.

This pattern is appropriate when the application owns the error experience or needs request context. It is unnecessary for a simple static page and adds an upstream dependency to an error path, so make sure the fallback service is more reliable than the service that failed.

Send an error to an application handler

A dynamic handler can generate a page, localize text, or record a request identifier. For an upstream-generated page whose returned status should be passed through, use the equals form without specifying a replacement status:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
error_page 404 = /404.php;

Nginx internally redirects to the handler, and the handler’s response status can be used instead of blindly forcing 404. Confirm that the handler is reachable under the active configuration and does not itself trigger the same error mapping indefinitely.

Application frameworks sometimes return their own error body or status before Nginx’s static error page is involved. If a proxied service is already producing the response, inspect the proxy location and upstream behavior rather than assuming a server-level error_page rule will replace every body. Place the rule in the context that handles the failing request and test an actual upstream failure.

Redirect the browser to another URL

An absolute URI makes Nginx send a redirect instead of an internal page:

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
error_page 403 http://example.com/forbidden.html;
error_page 404 =301 http://example.com/notfound.html;

Without an explicit equals status, Nginx uses a 302 redirect. The equals form allows 301, 302, 303, 307, or 308. A redirect changes the address visible in the browser, introduces another request, and can alter caching and method behavior according to the redirect status and client. Use it for a purposeful migration or centralized error service, not merely to style a local 404.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Place the directive where the failure occurs

Error-page settings are inherited only when the current configuration level defines no error_page directives. A location that declares its own error mapping stops inheriting the parent set. This explains why a rule in one server block may work for ordinary static files but not for a proxied or nested location.

When debugging scope, identify the selected virtual host, then the most specific location for the failing URI. Check each level for an error_page declaration. If a separate server block listens on the same address, port, or name, edit the configuration that actually receives the request.

Validate and reload safely

  1. Edit the intended Nginx configuration and save the HTML files under the configured root.
  2. Validate syntax with nginx -t. If your installation uses a wrapper or a nonstandard binary, confirm the command with that installation’s command-line help.
  3. Reload without stopping the service: nginx -s reload.
  4. Request a known missing URL and record the HTTP status, response body, and browser URL.
  5. Review access.log and error.log if the result is unexpected. The logs reveal which URI was requested, whether the error document was found, and whether an upstream generated the response.

A reload applies configuration to new workers while allowing existing connections to finish. If validation fails, do not reload the invalid file; correct the reported line first.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a custom page that does not appear

The error document produces another 404

Check the active root, the exact filename, permissions, and case. A mapping to /404.html must find the file at the root plus that URI. Also look for a location rule that intercepts /404.html and sends it elsewhere.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The direct test returns 404

If the target location contains internal;, a client request to that URI must return 404. Test by requesting a separate missing resource. Remove internal only if the error document is intentionally public; leaving it enabled prevents accidental direct access.

The rule works for one URL but not another

The requests may select different server or location contexts. Compare the host name, port, URI prefix, and nested locations. Remember that a child context with its own error_page declarations does not inherit the parent’s set.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

The upstream body replaces your page

A proxied application may return its own status and body. Inspect the upstream response in the logs and place the mapping in the proxy-handling context. If the application should own the response, route to a named location or dynamic handler instead of forcing a static page.

The browser URL changes unexpectedly

An absolute target is an external redirect, not an internal error document. Replace it with a local URI for an unchanged address, or choose the redirect status deliberately if the URL change is required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A POST becomes a GET

That is the normal behavior of an internal redirect to a URI for methods other than GET and HEAD. Use a named location when preserving the method and original URI is important.

The page still exposes a version

Generated Nginx error pages and the Server response header can include the Nginx version. Set server_tokens off; in an applicable configuration context:

server_tokens off;

This controls Nginx’s version emission; it does not remove identifying information added by an upstream application or another proxy. Inspect the actual response headers after reloading.

Design the page for recovery, not disclosure

A useful error page states what happened in plain language and gives the visitor a next action. Offer a home link, site search, a stable navigation path, or a support/contact route. Keep contrast, keyboard focus, heading order, and text size accessible, and make the page usable without JavaScript or external assets that may fail during an outage.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not include filesystem paths, stack traces, database errors, private hostnames, secrets, request headers, or diagnostic data intended only for logs. Put correlation identifiers in server-side logs rather than displaying sensitive context to every visitor. Keep 404 and 50x documents small enough to serve when the application or asset pipeline is unavailable.

Complete static configuration example

The following server block combines a document root, explicit file lookup, separate 404 and 50x pages, and version suppression:

server {
    listen 80;
    server_name example.com;
    root /var/www/example;

    server_tokens off;

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location / {
        try_files $uri $uri/ $uri.html =404;
    }

    location = /404.html {
        internal;
    }

    location = /50x.html {
        internal;
    }
}

Place both documents directly beneath /var/www/example, validate with nginx -t, reload with nginx -s reload, and test a missing path plus a controlled upstream failure. The logs should show the original failing request and the internal error-document request without exposing the document as a public resource.

Production checklist

  • The HTML file exists beneath the root used by the selected server and location.
  • The file is readable by the Nginx worker account.
  • Each required status has an intentional mapping, with grouped 500-series codes only when one message is appropriate.
  • The target location is marked internal when direct access is not needed.
  • You understand whether the target preserves the status, changes it, invokes an upstream, or redirects the browser.
  • You have considered the method change caused by URI-based internal redirects.
  • Nested locations and proxy handlers do not override the mapping unexpectedly.
  • nginx -t succeeds before nginx -s reload.
  • A missing URL, the error-document URI, and an upstream failure have each been tested separately.
  • Access and error logs contain enough operational detail without putting sensitive diagnostics in the response.
  • server_tokens off; is enabled if version disclosure is undesirable, and the resulting headers have been checked.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

404 errorsHTTP status codesNGINXServer Configurationweb server administration

Leave a reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.