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

On a LEMP server, a missing URL can be handled by Nginx or by WordPress. For normal WordPress permalinks, put try_files $uri $uri/ /index.php?$args; in location / so WordPress can resolve virtual URLs and render its own 404.php or block-theme templates/404.html. Use Nginx’s error_page 404 /404.html; only when you deliberately want a lightweight, static page that works without PHP.

How 404 handling works on a LEMP WordPress site

There are two separate decisions behind a WordPress 404:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Which layer decides that the URL is missing? Nginx can stop the request, or it can pass the request to WordPress.
  • Which layer renders the response? Nginx can serve a static file, while WordPress can load the active theme’s 404 template.

These decisions are related but not identical. A request can be recognized as missing by Nginx and then internally mapped to a static error document. Alternatively, Nginx can pass an unknown path to index.php, allowing WordPress to determine whether it is a page, post, archive, or genuine not-found URL.

The request path in practice

  1. Nginx receives the hostname and URI and selects the matching server block.
  2. The location / rule checks whether the URI maps to a real file or directory.
  3. If neither exists, the final try_files argument sends the request internally to /index.php.
  4. WordPress evaluates its rewrite rules and decides whether the path matches content. If it does not, the theme’s 404 template is selected.

This flow explains why a physical file such as /wp-content/uploads/logo.svg can be served directly while a virtual URL such as /news/example-story still works without a matching directory. The query string is retained, so parameters used by WordPress or a search request are not silently discarded.

#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:Upgraded 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.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.

The usual WordPress route is:

location / {
    try_files $uri $uri/ /index.php?$args;
}

try_files checks the requested path against the filesystem. If a matching file or directory is not found, the final argument sends the request to WordPress’s front controller and preserves the original query string. WordPress then applies its rewrite and template hierarchy. This is the key distinction between a working WordPress 404 and a generic Nginx 404.

Choose the layer that should own the 404

Choose one primary owner for each class of error rather than adding directives copied from unrelated Apache configurations. The following trade-offs determine the right design.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision factor Nginx static 404 WordPress-generated 404
PHP or WordPress availability Works even when PHP-FPM or WordPress is unavailable, provided Nginx can read the static file. Requires a functioning WordPress installation and PHP-FPM.
Visual consistency Uses the HTML and CSS you place in the static document; it does not automatically inherit the active theme. Uses the site’s header, footer, navigation, styles and theme conventions.
Search and dynamic navigation Only what you implement in static HTML; no WordPress search form or menu logic by default. Can use theme functions, menus, search forms and other WordPress-aware content.
Where it is configured Nginx server block and a file such as /404.html. Active theme, using 404.php for a classic theme or templates/404.html for a block theme.
Request overhead Very small and independent of PHP execution. Runs through the normal WordPress request path.
HTTP status Nginx’s error_page processing can return the original 404 status. WordPress supplies the not-found response; do not replace it with a redirect or a forced 200 response.

Static handling also makes caching straightforward because the error document is an ordinary file and does not require a PHP execution for each request. A theme-driven page can still be cached by a reverse proxy or WordPress cache, but that cache must be tested so it does not turn a not-found response into a cached 200 page. In either design, monitor the status code as well as the appearance of the page.

Use the static option for an emergency or server-level page, for a highly minimal error endpoint, or when the page must remain available during a PHP or WordPress outage. Use the theme option when visitors need the site’s normal design, navigation and search experience.

Prepare the Nginx and WordPress configuration

Confirm the document root

The Nginx root must be the directory that contains the WordPress installation. In the example below it is /var/www/example.com. If the root points one directory above or below the actual installation, Nginx will fail to find static assets and may never reach the expected front controller. Check the root in the server block selected for the real hostname, not merely in a default site that is no longer active.

Use a WordPress-aware server block

A minimal server block for the WordPress-handled approach looks like this:

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.
server {
    server_name example.com;
    root /var/www/example.com;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ .php$ {
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }
}

The regular-expression PHP location sends PHP scripts to PHP-FPM rather than serving them as downloadable files. The socket shown is an example; your operating system or PHP version may use a different socket path, so retain the path that belongs to your installed PHP-FPM service. fastcgi_intercept_errors on; is part of the documented WordPress Nginx pattern and allows Nginx to process errors generated by the upstream application when appropriate.

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

Why the final try_files argument matters

The first argument, $uri, checks for an actual file. The second, $uri/, checks for a directory. The final argument, /index.php?$args, is not a redirect visible to the visitor: it is the internal route that gives WordPress the original request and query parameters. Without that fallback, a request such as /a-post-that-exists has no physical directory to match and Nginx can return its own 404 before WordPress sees it.

Do not append =404 to this location when you expect WordPress to resolve pretty permalinks. A configuration such as try_files $uri $uri/ =404; deliberately terminates unmatched paths at Nginx and prevents WordPress’s rewrite system from handling them.

Keep the PHP boundary explicit

Only requests ending in PHP should enter the PHP location. Static assets, uploads and the error document should remain ordinary files. If a malformed request can reach a PHP handler unexpectedly, fix the location rules before concentrating on page design. A 404 page is not a substitute for a safe FastCGI configuration: source code must never be exposed to visitors.

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

Configure a static Nginx 404 page

Choose this method when the error page must remain independent of WordPress. Create a file such as /var/www/example.com/404.html containing the complete static markup you want visitors to see. Then add the following directives inside the relevant server block:

error_page 404 /404.html;

location = /404.html {
    internal;
}

error_page 404 /404.html; tells Nginx to internally process the error through that URI. It does not issue a client-side redirect to another address. The internal modifier prevents visitors from requesting the error endpoint as a normal public page; Nginx can use it for error processing, but a direct request to /404.html is not treated as an ordinary resource.

Keep the target file under the configured document root, or use an explicit location and file path that matches your deployment. Include any CSS needed by the page in a way that remains available when WordPress is down. Do not point the directive at the home page merely to avoid showing an error. A home-page redirect or a forced 200 response conceals the fact that the requested resource does not exist, which is confusing for users and harmful to monitoring and indexing.

When to combine static and WordPress handling

It is possible to use WordPress for ordinary missing content while retaining a static page for failures that occur before WordPress can run, but the locations and error behavior must be tested carefully. A broad error_page 404 /404.html; can replace the theme-rendered page when Nginx intercepts the response. If the requirement is specifically a theme-designed 404, omit the broad static directive and let try_files route the request to WordPress. Document which layer owns which class of failure so a later server change does not silently override the intended design.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【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.

Build a WordPress theme-driven 404 page

When the page should look like the rest of the site, leave the request on the WordPress route and edit the active theme.

Classic themes: 404.php

Create or edit 404.php in the active theme directory. WordPress’s theme hierarchy uses this file when a visited URL does not exist. A compact classic-theme template can be structured like this:

<?php
get_header();
?>

<main id="primary" class="site-main">
    <h1>Page not found</h1>
    <p>The address may be incorrect, or the page may have moved.</p>
    <?php get_search_form(); ?>
</main>

<?php
get_footer();

Use the theme’s existing markup, classes, escaping, localization and accessibility patterns rather than treating this as a standalone HTML page. A useful template gives visitors a clear explanation and a recovery path, such as search or navigation. Do not call a redirect to the front page from this template. The visitor should receive a real 404 response for a missing URL.

Block themes: templates/404.html

Block themes use the templates hierarchy. Add or edit templates/404.html in the active block theme and assemble the page with blocks for the heading, explanatory text, navigation and search. The block-theme hierarchy checks 404.html before falling back to index.html, so a dedicated file lets you control the not-found layout without changing every template.

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

After changing a theme file, clear any page cache that might be serving an older response, then test a URL that cannot exist. The HTTP status must remain 404 even when the visual page is fully branded. Check both logged-out and logged-in requests if your caching setup treats those audiences differently.

Apply the change safely

  1. Back up the server block and template. Save a copy of the Nginx configuration you will edit and the current 404.php or templates/404.html. This gives you a direct rollback if a syntax or template error appears.
  2. Edit the correct server block. Put the try_files rule in the server block for the requested hostname. If you use a static page, add error_page 404 /404.html; and the exact internal location there.
  3. Check PHP-FPM routing. Verify that the PHP location includes the FastCGI configuration and points to the active PHP-FPM socket. A PHP file that downloads instead of executing indicates a handler problem that should be corrected before exposing the site.
  4. Validate syntax before reloading. Run:
sudo nginx -t

Only continue when Nginx reports a successful configuration test. A failed test leaves the running configuration untouched, so fix the reported file and line before attempting a reload.

  1. Reload Nginx without stopping it. Use the normal command for your platform, for example:
sudo nginx -s reload
  1. Test three request classes. Request an existing static file, an existing WordPress permalink and a deliberately nonexistent URL. This separates filesystem lookup, WordPress routing and 404 rendering problems.
  2. Inspect the status directly. Run:
curl -I https://example.com/this-url-should-not-exist

The response should contain HTTP status 404, not 200 and not a redirect. Also load the URL in a browser to verify the expected static or theme-designed content. Repeat the test with a query string when your site relies on parameters, confirming that the fallback still reaches WordPress with those arguments intact.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common 404 failures

Every pretty permalink returns an Nginx 404

Check that location / contains the exact WordPress fallback:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
try_files $uri $uri/ /index.php?$args;

Then verify that root points to the WordPress document directory and that the request is reaching the intended server block. If the configuration instead ends with =404, Nginx is intentionally stopping the request before WordPress can resolve the permalink.

The page is the plain Nginx error instead of the theme page

Look for an error_page 404 directive in the active server block or an included configuration. A static error mapping can replace the response that WordPress would otherwise generate. Also inspect every try_files rule for an early =404 termination. Remove or narrow those directives if the desired owner is WordPress.

PHP files download or appear as source code

Stop normal traffic to the affected site and correct the PHP location. PHP scripts must be passed to PHP-FPM through FastCGI; they must never be served as ordinary static files. Check the regular-expression PHP location, its include fastcgi.conf; line and the fastcgi_pass socket. Re-run sudo nginx -t and reload only after the handler is correct.

The custom page itself cannot be found

Confirm that the file name is exactly 404.html, that it is under the configured root, and that the exact-match location is in the same server block that contains error_page. A typo in the root or file name can create a second error while Nginx is trying to render the first one.

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

The site shows a 200 status for a missing URL

Check for a redirect to the home page, a rewrite that ends at a normal content URL, or application code that forces a successful status. A custom 404 must explain that the resource is missing while preserving HTTP 404. Test with curl -I rather than relying only on what the browser displays.

Apache instructions do not work

Nginx does not read Apache’s per-directory .htaccess files. Rewrite and permalink behavior belongs in the Nginx server configuration. Copying an Apache recipe unchanged can leave WordPress without its front-controller fallback and produce false 404 responses.

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.

Hosting and operational considerations

If you do not have access to the Nginx server block, choose a managed WordPress or VPS hosting plan that explicitly permits Nginx configuration changes. A control panel that only exposes Apache or .htaccess settings cannot apply the directives in this guide. Confirm who owns PHP-FPM, configuration testing and reloads before moving a production site, and keep the static fallback available if your availability requirements demand an error page during application maintenance.

Verification checklist for production

  • The active server block has the correct WordPress root.
  • location / uses try_files $uri $uri/ /index.php?$args; when WordPress should own missing-content decisions.
  • The PHP location passes scripts to PHP-FPM and does not expose source files.
  • A static design uses error_page 404 /404.html; with an internal error location, and is not enabled accidentally over a theme-driven design.
  • Classic themes contain the intended 404.php; block themes contain templates/404.html.
  • sudo nginx -t succeeds before every reload.
  • An existing file, an existing permalink and a deliberately nonexistent URL have each been tested.
  • curl -I https://example.com/this-url-should-not-exist reports 404.
  • The missing page offers a useful recovery path without redirecting the request to a normal 200 page.

Which configuration should you use?

For most public WordPress sites, keep the Nginx server block focused on routing and let WordPress render the 404 through the active theme. That preserves the site’s navigation, search and design while keeping the correct status. Add a static Nginx error page when independence from PHP is a requirement or when the page is intended for failures that occur outside WordPress. The decisive setting is whether unmatched requests reach /index.php or are terminated and mapped by Nginx first.

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

Frequently Asked Questions

How do I configure a custom 404 page for WordPress on Nginx?

Put try_files $uri $uri/ /index.php?$args; in location / and customize the active theme’s 404.php or templates/404.html. This keeps the response in WordPress and preserves the site’s normal design.

How do I serve a static Nginx 404 page instead?

Create 404.html under the configured document root, add error_page 404 /404.html;, and protect an exact-match location = /404.html with internal;. Test that the response remains HTTP 404.

Why does WordPress show an Nginx 404 for every pretty permalink?

The location / block is usually missing the WordPress fallback, the root points to the wrong directory, or a rule ending in =404 stops the request before it reaches index.php.

Why is the Nginx page displayed instead of my theme’s 404 template?

Find an active error_page 404 directive or an early try_files ... =404. Either can terminate or replace the request before WordPress renders its theme template.

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.

How can I verify that a custom 404 still returns the correct status?

Request a deliberately nonexistent URL with curl -I https://example.com/this-url-should-not-exist. Confirm the status is 404, not 200 and not a redirect, then inspect the page in a browser.

What should I do if PHP files download from the site?

Stop and correct the PHP location immediately. Include the FastCGI configuration and pass scripts to the active PHP-FPM socket; never allow Nginx to serve PHP source as a static file.

The Bottom Line

Use try_files $uri $uri/ /index.php?$args; when WordPress should own missing URLs and render the active theme’s 404 template. Use error_page 404 /404.html; only for a deliberately independent static page. After editing, run sudo nginx -t, reload safely, and verify a nonexistent URL returns HTTP 404 rather than a redirect or 200 response.

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.