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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

The reliable way to create a custom NGINX error page is to save a static HTML file under the active server root, map the relevant status with error_page, validate the configuration, and reload NGINX. A minimal 404 setup uses error_page 404 /404.html;; the URI is handled internally, so the visitor keeps the original address and normally receives a 404 response.

This guide shows how to build branded 404 and 5xx pages, share one page across several statuses, preserve an upstream response when necessary, redirect to another URL, diagnose pages that do not appear, and reduce NGINX version disclosure.

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

What NGINX custom error pages actually do

NGINX generates an error response when it cannot serve a requested resource, an upstream fails, or a rule deliberately returns a status. By default, the response may contain NGINX-generated HTML. The error_page directive lets you replace that body with a local URI, send processing to a named location, pass the request to an application handler, or redirect the browser elsewhere.

The mapping is configured in the http, server, or location context (and in an if block inside a location). A local mapping is not the same as an HTTP redirect: NGINX performs an internal redirect, the browser address does not change, and the original status is retained unless you explicitly select another response code.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Prepare the file and configuration

Choose the active document root

NGINX combines the request URI with the configured root path to find a file. If a server has root /var/www/example;, a request for /404.html maps to /var/www/example/404.html. Put the error document in that exact directory, or change the URI and root so they resolve to the intended file.

Check which server block receives the hostname and port you are testing. A correct directive in an unused virtual host has no effect on the request that fails.

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

Make the page safe and useful

Keep the document static unless there is a good reason to invoke an application. A useful error page identifies the problem in plain language, offers a link back to a known working location, and provides search or support guidance where appropriate. Do not expose stack traces, upstream hostnames, credentials, internal filesystem paths, request headers, or other diagnostic data to visitors.

Example static HTML

<!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>We could not find that page</h1>
    <p>The address may be wrong or the page may have moved.</p>
    <p><a href='/'>Return to the home page</a></p>
  </main>
</body>
</html>

Save this as /var/www/example/404.html when the server root is /var/www/example. Use relative assets sparingly: an error response can occur at any URL depth, and relative image, CSS, or script paths may resolve unexpectedly. Inline critical styling or use root-relative paths such as /assets/errors.css.

Create a basic custom 404 page

Add the mapping and an optional protection rule to the applicable server block:

server {
    root /var/www/example;

    error_page 404 /404.html;

    location = /404.html {
        internal;
    }
}
  1. Create 404.html below the configured root.
  2. Add error_page 404 /404.html; to the server handling the request.
  3. Add the exact-match location with internal; if visitors should not request the document directly.
  4. Validate and reload NGINX.
  5. Request a path that does not exist and confirm that the custom body appears while the response status remains 404.

The internal; directive is optional hardening. It allows NGINX’s internal error handling to fetch the document but returns a 404 when a client requests /404.html directly. This prevents the error asset from becoming a normal public endpoint, although it does not hide the HTML if someone receives it as the body of an error response.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Use one page for several status codes

When the same explanation is appropriate for several server failures, list the codes on one directive. NGINX supports this grouped form:

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

The first line handles missing resources. The second covers an application error, a bad gateway response, temporary unavailability, and a gateway timeout with one static page. Keep the wording broad enough to fit every status, or use separate pages when visitors need different recovery instructions.

Suggested status groups

  • 404: The requested resource is absent. Offer navigation, search, or a corrected link.
  • 403: Access is refused. Explain that permission is required without revealing whether a sensitive resource exists.
  • 400: The request is malformed. Ask the client or calling system to correct its input.
  • 500: The application or server encountered an unexpected failure.
  • 502: NGINX received an invalid response from an upstream.
  • 503: The service is unavailable, often temporarily.
  • 504: An upstream did not respond in time.

Understand status, URL, and method behavior

The form of error_page determines what the client sees. The core syntax is:

error_page code ... [=response] uri;
Configuration form Keeps original status? Changes browser URL? Method behavior Typical use
error_page 404 /404.html; Yes, unless overridden No Internal redirect changes methods other than GET and HEAD to GET Branded static 404 or 50x page
error_page 404 = /handler; Handler or upstream can determine it No Internal redirect rules apply Application-generated body or pass-through status
error_page 404 = @fallback; Backend or named location decides No URI and method are preserved for error processing Proxy or application fallback
error_page 404 =301 http://example.com/notfound.html; No; the selected redirect status is returned Yes The browser follows the redirect according to HTTP rules Legacy URL migration or a centralized error site

For local URI processing, NGINX performs an internal redirect and changes the request method to GET for every method other than GET and HEAD. That matters when a failed POST, PUT, or DELETE must reach a handler with its original method or body. Use a named location in that case.

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

Route failures to a named location or upstream

Preserve the request for a proxy fallback

A named location is useful when the fallback is handled by an application or reverse proxy:

location / {
    error_page 404 = @fallback;
}

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

The = form tells NGINX to use the response generated by the target rather than automatically forcing the original 404. A named location avoids the URI rewrite that accompanies a normal internal URI redirect and preserves the request URI and method for error processing. Confirm that the fallback application can safely handle every method and body it may receive.

Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Pass through an upstream-generated status

If a script or application endpoint should generate the error document and its own status, point error_page at that endpoint with an equals sign:

error_page 404 = /404.php;

The application can then return a body and status appropriate to the request. This pattern adds application work to an error path, so protect it from loops: the handler must not itself trigger the same error mapping indefinitely, and it should remain available when the primary application is failing.

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

Redirect an error to another URL

NGINX can send an external redirect instead of serving a local page:

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 by default. With the equals form, you can select 301, 302, 303, 307, or 308. A redirect changes the browser-visible URL, adds another request, and may expose a centralized error host. Permanent codes such as 301 and 308 can also be cached by clients and intermediaries, so use them only when the destination is genuinely permanent.

Use a local page when the original URL should remain visible and the error should retain its status. Use an external redirect for a deliberate migration, a legacy address policy, or a separately managed error service. Do not redirect every failure to the home page: visitors and monitoring systems lose the distinction between a missing resource and a successful page.

Control which requests become 404 responses

Static NGINX returns 404 when a requested file or directory does not exist. For applications that support clean URLs, use try_files to define the lookup order explicitly:

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.
Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
location / {
    try_files $uri $uri/ $uri.html =404;
}

NGINX checks the requested file, then directory, then an .html variant. If none exists, =404 returns the selected status, which can then be handled by the server’s error_page 404 mapping. This makes the fallback predictable and prevents an unintended pass to another handler.

Remember that try_files and error_page solve different problems. try_files decides whether a file or directory exists and what to do when it does not. error_page decides how NGINX presents a status that has already been generated.

Place directives in the context that handles the failure

Directive inheritance can make a configuration appear correct while leaving a request uncovered. An error_page setting is inherited from the previous configuration level only when the current level defines no error_page directives. If a nested location has its own error-page directive, it does not automatically combine that list with the parent.

  • Put a site-wide mapping in the relevant server block.
  • Put a mapping for only one route in that route’s location.
  • Check included configuration files and the selected virtual host when several sites share one NGINX process.
  • Test both static misses and upstream failures; they may be handled by different locations.

Validate, reload, and test safely

  1. Back up the active configuration or make the change in version control.
  2. Run nginx -t to check syntax and referenced files. If your installed build uses different command-line behavior, confirm the validation option with nginx -h or its local documentation.
  3. Reload without stopping workers: nginx -s reload.
  4. Request a deliberately nonexistent path, such as /does-not-exist- test, using a client that shows both headers and body.
  5. Check the response status, Content-Type, body, and browser URL.
  6. Review access.log and error.log if the result is unexpected.

Test from outside any application cache and test with both GET and a representative non-GET method when your site accepts APIs or forms. A cached old page, a service worker, or an upstream-generated body can make a correct NGINX change look ineffective.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fix a custom page that does not appear

Symptom Likely cause What to check
The response is still the standard NGINX page The directive is in the wrong server or location context Confirm the hostname, port, listen address, and included configuration that handled the request.
The custom URI produces another 404 The HTML file is outside the active root or the path is misspelled Resolve the URI against root, verify permissions, and request the file through the same server block.
/404.html itself returns 404 The location is marked internal and was requested directly Test a missing resource instead; direct access is intentionally rejected.
The status is 200 instead of 404 The target handler returned its own status or the mapping used an explicit replacement Inspect = usage, upstream headers, and the handler’s response code.
The address bar changes An external redirect was configured Replace the redirect with a local URI or named location if the original URL must remain visible.
A POST becomes a GET A normal local URI mapping performed an internal redirect Use a named location when method and URI preservation are required.
An upstream’s error body wins The proxied application generated its own response Decide whether the application should own the page or route the status through NGINX with an appropriate = mapping.
Changes have no effect after editing Configuration was not validated or reloaded, or a different NGINX instance is serving traffic Run the validation command, reload, inspect logs, and verify the process and configuration path.

Check the filesystem path directly

For a mapping of /404.html and root /var/www/example, the expected file is /var/www/example/404.html. A common mistake is placing it in a distribution’s default document directory while the active virtual host uses a different root. Another is defining alias in a location and assuming the file maps like root; keep the error URI and its filesystem mapping unambiguous.

Look for recursive error handling

If the error document itself triggers a 404, NGINX can repeatedly enter error handling or return a generic failure. Make the target a real, readable file, keep its exact-match location simple, and avoid applying an unrelated rewrite or access rule to that URI.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Reduce NGINX version disclosure

Generated error pages and the Server response header can disclose the NGINX version. Set this directive in the http or appropriate server context when that information should not be emitted:

server_tokens off;

This controls NGINX’s version string in generated error pages and the Server header. It does not replace broader hardening: review response headers, debug output, upstream banners, and error content separately. Custom HTML should never include software versions, deployment identifiers, hostnames, or filesystem paths unless there is a specific operational reason to reveal them.

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

Design an error page that helps users and operators

  • Use a clear heading such as “Page not found” or “Service temporarily unavailable.”
  • Explain the next action: check the address, return home, search, retry later, or contact support.
  • Keep navigation available even when the failed URL is deeply nested.
  • Provide sufficient color contrast, a meaningful document title, keyboard-accessible links, and a language declaration.
  • Do not rely on JavaScript, external fonts, or third-party assets for the essential message.
  • Keep 5xx wording neutral and avoid blaming the visitor.
  • Log technical details on the server side rather than printing them into the response.

A 404 page can safely identify a missing public URL. A 403 or 5xx page should reveal less, because the distinction between “missing” and “forbidden,” internal service names, and detailed failure causes can aid reconnaissance or leak implementation details.

Choose the right implementation

Use a local static URI when

You need a fast, branded page that works even when the application is unavailable. It keeps the original URL and status, has minimal dependencies, and is straightforward to cache and test. The trade-off is that non-GET methods become GET during the internal redirect.

Use a named location when

A proxy or application must receive the original URI and method, or when the backend should decide the final status. This is more flexible but introduces an additional dependency and requires careful loop prevention and capacity planning during an outage.

Use an external redirect when

The error destination intentionally lives at another URL, such as a legacy migration endpoint or a centrally managed site. It changes the browser address, incurs another request, and returns a redirect status rather than the original error code.

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.

Production checklist

  • The HTML file exists below the root used by the receiving server block.
  • Each status mapping is declared in the context that handles the failure.
  • Grouped codes share a page only when their user guidance is genuinely compatible.
  • The target location is protected with internal; when direct access is unnecessary.
  • Named locations are used where method or URI preservation matters.
  • Redirect codes are intentional and match the permanence of the destination.
  • try_files rules return the expected status for missing content.
  • nginx -t succeeds before the reload.
  • nginx -s reload has been issued to the instance serving traffic.
  • Tests confirm status, body, headers, URL behavior, and at least one non-GET request where relevant.
  • Access and error logs show no recursive handling, permission failures, or unexpected upstream responses.
  • Custom pages contain no secrets, stack traces, internal paths, or unnecessary version information.

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.