Bobcares

How we fixed Nginx WordPress permalinks 404 error

by | May 6, 2019

Nginx make sites faster. It definitely has an upper edge in serving static content. That’s why, many WordPress users switch to Nginx.

Often, this switch cause Nginx WordPress permalinks 404 errors. This happens as Apache’s rewrite rules do not work with NGINX.

Therefore, fixing WordPress websites is one of the common task that we do as part of our Server Administration Services.

Today, we’ll see how Bobcares’ Engineers fixed Nginx WordPress permalinks 404 error for one of our customer.

Details of WordPress permalinks 404 error

We’ll begin with seeing the details of the error reported by the customer. The Help-desk request said:

In my domain, only the home page is working, where as every other page returns a 404 not found error. I
think this is either due to .htaccess file, permalink settings, or Nginx Configuration? Please fix!

The customer had website hosted on a Plesk server. He recently switched to Nginx from Apache. That’s when he started getting 404 or Page not found errors.

 

What causes permalinks 404 error in Nginx?

WordPress come with the option to create permanent links to blog posts on the website.  And, the links can be created based on post name, post number, date, etc.

Now, its time to see what causes the Nginx wordpress permalinks 404 error.

Basically, customer choose PHP-FPM as the PHP handler, as it is the handler that WordPress recommends. And, to take advantage of NGINX, we recommend customers to enable PHP-FPM on all domains that serve PHP content.

Unfortunately, mod_security rules will not work with NGINX, and .htaccess rewrite rules and restrictions will no longer apply. Nginx and Apache rewrite rules have totally different format. The directives in Apache like Rewritecond, RewriteRule, etc. take its equivalents in Nginx configuration.

This means that WordPress permalink rewrites will no longer work after switching the web server.

 

Steps for fixing Nginx wordpress permalinks 404 error

Luckily, there are several methods to fix the WordPress permalinks on Nginx. Let’s take a look at each of them.

 

1. Converting rewrite rules to Nginx format

A quicker method to fix the permalink error is to convert the Apache rewrite rules to Nginx format. Either we can manually rewrite the rules or use various plugins for automatic conversion.

For example, in servers with Plesk control panel, there comes an extension like “htaccess to nginx“. By using this extension, it would rewrite the custom Apache directives according to the rules of nginx syntax. The plugin details are as shown below.

We just had to add the rules in the Additional Nginx directives section inside the domain settings as shown below.

That fixed the permalinks and the website started working again.

 

2. Modifying Nginx configuration

Similarly, modifying the Nginx configuration also helps in solving the WordPress permalinks 404 error. Here, within the per domain Nginx configuration file for the domain, our Support Engineers edit the following location block within the server block:

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

Further, we reload the Nginx configuration for the changes to take effect.

 

3. Tweaking Proxy mode

Similarly in Plesk servers having Apache with Nginx as reverse proxy, tweaking domain’s setting also solve the permalink errors. The .htaccess is ignored if Apache is turned off for the domain. And, it results in Permalink 404 errors.

Therefore, in some cases, to solve the error, we turn ON the option Proxy mode from Plesk > Domains > example.com > Apache & nginx Settings.

[Finding Nginx WordPress permalinks 404 error trouble? We can fix your website.]

 

Conclusion

To be precise, Nginx wordpress permalinks 404 error occurs when the rewrite rules do not follow the Nginx format. The fix involves converting the rules, modifying Nginx configuration and many more. Today, we saw how our Support Engineers solved the error for our customer and made permalinks working again.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

7 Comments

  1. igens

    Thanks it helped me, Actually my file location was

    location / {
    try_files $uri $uri/ 404;
    }

    Reply
    • Sijin George

      Glad to know that our post was helpful for you 🙂

      Reply
  2. NinjaCode

    I had the same problem and this helped me out, thanks!

    Reply
    • Maheen Aboobakkar

      Hello,

      We’re glad you were able to solve the issue by following the instructions in this article.

      Reply
  3. Thiago

    MAAAAAN, thanks for your pot, it’s 2022 and this post keep helping people

    Reply
    • Maheen Aboobakkar

      Hello Thiago,

      We’re glad you were able to solve the issue by following the instructions in this article.

      Reply
  4. Rey

    just replace this from nginx’s default line.

    try_files $uri $uri/ /index.php$is_args$args;

    Reply

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF