When WordPress home pages load but post URLs return 404 on Nginx, the usual cause is a missing or misplaced fallback in the active server block. Nginx does not read .htaccess, and WordPress cannot write Nginx configuration for you. Put the rewrite logic in the correct Nginx configuration, make the document root and PHP-FPM mapping agree with the installation, test with nginx -t, reload, and then flush WordPress permalinks if necessary.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
Why WordPress rewrites fail on Nginx
Apache-based WordPress tutorials often tell you to edit .htaccess. That advice does not apply to Nginx. Nginx has no per-directory configuration file equivalent to Apache’s .htaccess or IIS’s web.config. Its routing rules live in the loaded Nginx configuration, normally inside a server {} block and one or more location {} blocks.
As an Amazon Associate I earn from qualifying purchases.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →WordPress also cannot generate those rules automatically. Changing the Permalinks screen in wp-admin changes WordPress’s URL rules, but it cannot edit a protected Nginx server block. The web server must first pass unknown, non-file paths to WordPress. If it does not, a request for a post such as /news/my-post/ is treated as a missing filesystem path and ends in a 404 before WordPress can resolve it.
The standard single-site fix
For a normal, root-level installation, set root to the directory that contains index.php, then use this pattern in the active virtual host:
#1 Best Overall
- 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.
server {
server_name example.com;
root /var/www/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include fastcgi.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
}
Replace the hostname, filesystem path, and PHP-FPM socket with the values on your server. The socket shown is an example, not a universal path. Some distributions use a versioned socket such as /run/php/php8.3-fpm.sock; others use a TCP address or a different directory.
What the try_files line does
try_files $uri $uri/ /index.php?$args; checks candidates from left to right. Nginx first looks for a real file matching the request, then a real directory. Existing CSS, JavaScript, images, and uploaded files are served directly. If neither candidate exists, Nginx internally redirects the request to /index.php and appends the original query string through $args. WordPress then decides whether the path is a post, page, archive, REST request, search, or another virtual URL.
Nginx’s directive semantics are important here: it constructs paths from the active root (or alias), checks them in order, and internally redirects to the final URI only when no earlier file or directory exists. A fallback ending in =404, or a location / block that omits try_files, prevents WordPress from seeing pretty URLs.
Four values that must agree
Most rewrite investigations become straightforward when these values are checked together rather than one at a time.
| Value | What must be true | Typical symptom when wrong |
|---|---|---|
Nginx root |
Points to the directory containing the intended WordPress files and index.php. |
Every virtual path appears missing; static files may also 404. |
| Public URL prefix | Root installs use /; subdirectory installs include the prefix, such as /blog/. |
Home page works but links under the prefix fail, or requests fall into the wrong application. |
| PHP-FPM target | fastcgi_pass reaches the PHP-FPM service that serves this site. |
502 responses, connection errors, or PHP files being downloaded. |
SCRIPT_FILENAME |
Resolves to the real PHP file on disk, commonly via $document_root$fastcgi_script_name. |
“File not found” from PHP-FPM even though the rewrite URI is correct. |
A correct rewrite cannot compensate for a wrong root or an unreachable PHP backend. Conversely, changing PHP code will not fix a request that never reaches index.php.
Understanding location matching and path mapping
Look at the complete configuration, not just the line you recently edited. A broad location / may be in one included file while a regex PHP location, another root, or an alias directive is defined elsewhere. Duplicate or competing locations can make a change appear ineffective when the request is actually being handled by a different block. The effective configuration shown by nginx -T is more reliable than guessing which file Nginx reads first.
Rank #2
- 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
Pay special attention to alias. try_files builds candidate filesystem paths from the active root or alias; if that mapping points one directory too high, Nginx will report a valid WordPress file as missing. A subdirectory URL also does not automatically mean the files are under a matching filesystem directory. Confirm both sides: the URL prefix used in the request and the actual path containing index.php.
Keep the query-string suffix in the fallback when parameters matter. For example, a search URL or an API request can carry arguments that WordPress needs. The form /index.php?$args preserves them during the internal redirect; removing ?$args can change the request WordPress receives even when the path itself looks correct.
A safe diagnostic sequence
Work through these checks in order. They separate configuration selection problems from routing, filesystem, and PHP problems.
- Identify the server block answering the hostname. Confirm the requested hostname, listen ports, TLS server, and
server_name. Make sure the block’srootis the one you intend. A perfect rule in an inactive or competing virtual host has no effect. - Dump the effective configuration. Run
sudo nginx -Twhen available. This tests the configuration and prints the complete loaded configuration, including included files. Search the output for duplicatelocation /blocks, regex PHP locations,try_files,rewrite,root, andaliasdirectives. The file you edited may not be included, or a later include may be selecting a different location. - Test syntax and referenced files. Run
sudo nginx -t. Nginx checks syntax and attempts to open files referenced by the configuration. Do not reload after a failed test; fix the reported file and line first. - Verify the fallback URI. A root installation normally ends with
/index.php?$args. A subdirectory installation must include its public prefix, for example/blog/index.php?$args. Keep$argswhen query-string parameters must survive the internal redirect. - Verify PHP handling separately. Check the PHP regex location, the PHP-FPM socket or address, and the value produced by
SCRIPT_FILENAME. A wrong socket or path is a backend issue, not a WordPress permalink issue. - Check filesystem mapping. Because
try_filesuses the activerootoralias, inspect the actual path that Nginx is testing. A document root one directory too high or too low makes valid WordPress URLs look nonexistent. - Reload only after a successful test. Use
sudo nginx -s reload, or the equivalent command from your service manager. Nginx loads the new configuration and gracefully retires old workers; a syntax error leaves the previous configuration running. - Test representative URLs while watching logs. Request the home page, a known post,
/wp-admin/, a static asset, and/wp-json/if the REST API is used. Compare access-log status codes with the error log. A 404 indicates routing or application resolution; a 502 points toward PHP-FPM; a successful HTML response with broken assets usually indicates a root or URL-prefix mismatch. - Flush WordPress’s rewrite state. In wp-admin, open Settings > Permalinks and save the current structure. If stale rules persist, switch temporarily to a default structure, save, switch back, and save again. This refreshes WordPress’s rewrite rules after the server route is fixed.
Root installation versus a subdirectory installation
Do not paste a root-level block unchanged when WordPress is publicly served below a prefix. The fallback must enter the directory where that installation’s index.php lives.
Recommended Free Tools
| Installation | Public URL example | Fallback | Primary checks |
|---|---|---|---|
| Root single site | https://example.com/ |
/index.php?$args |
Root contains WordPress index.php; location / is active. |
| Subdirectory site | https://example.com/blog/ |
/blog/index.php?$args |
Prefix appears in the location and fallback; WordPress URL settings match the layout. |
| Multisite network | Subdomain or subdirectory network | Use the documented network-specific rules | Network type and WordPress version determine additional rewrites and safeguards. |
Configuration for WordPress in /blog/
A directory-specific example looks like this:
location /blog/ {
try_files $uri $uri/ /blog/index.php?$args;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.*)$;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
The prefix, PHP version, socket path, and document root are environment-specific. Adapt each one rather than copying the example literally. The critical distinction is the fallback URI: sending /blog/article/ to /index.php at the domain root can invoke a different application or produce a 404, while /blog/index.php?$args enters the correct WordPress front controller.
Also verify the WordPress “site address” and “WordPress address” settings against the actual layout. Nginx can route a request correctly while WordPress generates links for another prefix if those values disagree.
Rank #3
- 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)
Single-site, multisite, and reverse-proxy differences
The short root-level snippet is intended for a single WordPress site served directly by Nginx and PHP-FPM. A multisite network is different: WordPress publishes separate Nginx guidance for subdirectory and subdomain networks, with additional rewrites and safeguards. Network type, DNS, TLS, and the WordPress version all matter, so use the matching multisite variant instead of adding isolated lines from a single-site example.
An Nginx reverse proxy in front of Apache adds another decision point. Determine which layer owns the public URL and whether the proxy forwards the expected path to Apache. A 404 generated by the front proxy will not be fixed by changing Apache, while a proxy that forwards correctly can still expose an Apache or PHP problem behind it. Inspect logs at both layers when you do not control a direct PHP-FPM setup.
Free tools Windows power users keep installed
One-click scans. No signup required.
On managed WordPress hosting, you may not have permission to edit server blocks, run nginx -t, or reload workers. In that case, give the host the failing URL, exact timestamp, response code, hostname, installation prefix, and relevant access or error-log entries. Ask whether custom Nginx rules are supported and which support channel handles permalink routing. Saving Permalinks alone cannot create a server fallback that the host has not configured.
Recognizing common failure patterns
Home page works, posts return 404
The home page may be a real index.php request, while a post is a virtual path. Check that the active location / contains the documented try_files fallback and does not end with =404. Then confirm the hostname selects that block, run nginx -t, reload, and test a known post.
Plain permalinks work but “Post name” fails
Plain permalinks can work without virtual-path routing because the URL often carries a query parameter that WordPress receives directly. “Post name,” custom structures, archives, and pages require Nginx to pass a non-file path to WordPress. Inspect try_files, the active root, and the selected server block before changing themes or WordPress code.
Requests download PHP files or return 502
These symptoms point to the PHP location rather than the permalink structure. A download usually means the request is not reaching a PHP handler. A 502 commonly means the configured PHP-FPM socket is absent, inaccessible, or running a different service. Confirm the socket exists, the PHP-FPM service is running, and SCRIPT_FILENAME resolves to a real file.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Rank #4
- 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
It works at / but fails under /blog/
Use a location /blog/ block with the /blog/index.php?$args fallback. Check that the Nginx root maps to the directory containing the installation, and that WordPress’s URL settings use the same public prefix. Look for a broader location / or another application that is intercepting the request.
Configuration changes appear to do nothing
The edited file may not be included, the request may select another virtual host, or workers may still be using the old configuration. Run sudo nginx -T to confirm the effective rule, then sudo nginx -t and sudo nginx -s reload. Check the reload result and test again while watching the logs.
A single-site snippet breaks a multisite network
Multisite networks have separate Nginx guidance for subdirectory and subdomain modes. Those variants add rewrites and safeguards that a single-site block does not contain. Identify the network layout and WordPress version, then use the matching official multisite configuration instead of adapting the generic root snippet.
Choosing the right fix path
| Situation | What to verify first | Who can apply the change |
|---|---|---|
| Self-managed Nginx with direct PHP-FPM | Active server block, root, try_files, socket, and SCRIPT_FILENAME. |
Someone with shell access and permission to test and reload Nginx. |
| Nginx reverse proxy in front of Apache | Which layer owns the public URL and whether the request reaches Apache with the expected path. | Administrators of both proxy and application layers. |
| Managed WordPress hosting | Whether the host permits custom server blocks and what support channel handles rewrites. | The host’s WordPress or Nginx support team if configuration access is restricted. |
| Multisite | Subdomain versus subdirectory network and the corresponding documented rules. | An administrator familiar with the network’s DNS, TLS, and Nginx layout. |
If you cannot inspect the effective configuration, read error logs, or reload Nginx, provide support with the failing URL, timestamp, response code, selected hostname, and the relevant log entries. Asking someone to “enable permalinks” without access to the server block cannot fix a missing Nginx fallback.
Operational checklist
- The request is reaching the intended
server {}block. rootpoints to the directory containing this WordPress installation’sindex.php.- The location fallback matches the installation:
/index.php?$argsat the root or/prefix/index.php?$argsbelow a prefix. - The PHP location reaches the correct PHP-FPM socket or address.
SCRIPT_FILENAMEmaps to the real script path.sudo nginx -tsucceeds before every reload.- The new configuration has been applied with a reload.
- Access and error logs have been checked for a home page, post, admin page, asset, and REST request where applicable.
- Settings > Permalinks has been saved after the server route was corrected.
- Multisite installations use their network-specific Nginx rules.
Once these checks pass, WordPress can resolve pretty URLs normally while Nginx continues serving real files directly. The fix is a server-routing correction, not an edit to a nonexistent Nginx version of .htaccess.
Frequently Asked Questions
Why does the WordPress home page work while every post URL returns 404 on Nginx?
The home page can resolve through a real index.php file, but a post URL is a virtual path. Add try_files $uri $uri/ /index.php?$args; to the active location / block, confirm the correct server block is selected, run nginx -t, reload, and test again.
Best Value
- 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.
Where is the Nginx equivalent of WordPress’s .htaccess file?
There is no per-directory equivalent that WordPress can edit. Put the routing rule in the loaded Nginx configuration, normally inside the site’s server {} and location {} blocks. WordPress cannot generate or save those server rules from wp-admin.
Why do Plain permalinks work but Post name permalinks fail?
Plain permalinks can pass a query parameter directly to WordPress. Post-name, page, archive, and custom structures require Nginx to send a non-file path to the front controller. Check try_files, the active root, and the selected virtual host before changing WordPress code.
What fallback should I use for WordPress installed in /blog/?
Use a location and fallback that include the public prefix: location /blog/ { try_files $uri $uri/ /blog/index.php?$args; }. Confirm that the document root contains the installation, that PHP-FPM receives the correct script filename, and that WordPress’s site and WordPress addresses use the same prefix.
What does a 502 error mean after adding a rewrite rule?
A 502 usually indicates a PHP-FPM problem rather than a permalink problem. Verify the fastcgi_pass socket or address, confirm PHP-FPM is running and reachable, and ensure SCRIPT_FILENAME resolves to the real PHP file. A PHP download generally means no PHP handler is processing the request.
How can I tell whether Nginx loaded the file I edited?
Run sudo nginx -T and inspect the complete effective configuration. Search for the server name, try_files, root, alias, and PHP locations. Then run sudo nginx -t and reload successfully; otherwise the previous worker configuration remains active.
Do I need to flush WordPress permalinks after fixing Nginx?
Save Settings > Permalinks after the server route is corrected. If URLs still behave as though old rules are present, switch to a default structure, save, switch back, and save again. This refreshes WordPress’s rewrite state; it does not replace the required Nginx fallback.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsCan I use the single-site snippet for WordPress Multisite?
Not safely. Multisite subdirectory and subdomain networks have separate Nginx configurations with additional rewrites and safeguards. Identify the network type and WordPress version and apply the matching multisite variant instead of pasting the generic single-site block.
The Bottom Line
For most single-site 404s, the fix is try_files $uri $uri/ /index.php?$args; in the active server block, with a matching root and working PHP-FPM mapping. Subdirectory and multisite installations need their own fallback paths. Verify the effective configuration with nginx -T, test with nginx -t, reload only after success, inspect logs, and then save WordPress permalinks.
Quick Recap
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.




