WordPress website shows 404 Not Found on all pages

Created:

2016-11-16 12:47:44 UTC

Modified:

2017-08-15 08:55:49 UTC

11

Was this article helpful?


Have more questions?

Submit a request

WordPress website shows 404 Not Found on all pages

Applicable to:

  • Plesk 11.5 for Linux
  • Plesk 12.0 for Linux
  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux

Symptoms

  1. A WordPress website shows "404 Not Found" errors on all the pages except home.
  2. nginx serves requests for the WordPress website.

Cause

  • WordPress permalinks are using .htaccess file to rewrite page URLs to http://example.com/page_name/.
  • nginx cannot read .htaccess file, this file can be read only by Apache.
  • When nginx + php-fpm is set to process PHP, Apache is not involved in the to process at all.

Resolution

For few websites, create additional nginx directives for a domain in Plesk > Domains > example.com > Apache & nginx Settings:

CONFIG_TEXT: if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
 set $test "${test}C";
}
if ($test = PC) {
 rewrite ^.*$ /index.php break;
}

Reconfigure website using the following command:

# /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain example.com

MAY NOT WORK WITH ONYX. If it is required to make globally on the server, create custom configuration template files:

  1. Copy default configuration templates as shown below:

    # mkdir /usr/local/psa/admin/conf/templates/custom
    # mkdir /usr/local/psa/admin/conf/templates/custom/domain
    # mkdir /usr/local/psa/admin/conf/templates/custom/domain/service
    # cp /usr/local/psa/admin/conf/templates/default/domain/nginxDomainVirtualHost.php /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
    # cp /usr/local/psa/admin/conf/templates/default/domain/service/nginxWordpressIndexing.php /usr/local/psa/admin/conf/templates/custom/domain/service/nginxWordpressIndexing.php

    Note: That any changes made in default configuration templates will be lost after installation of Plesk microupdates.

  2. In file /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php replace section:

    location ~ /$ {
    <?php echo $VAR->domain->physicalHosting->proxySettings['directoryIndex'] ?>
    }

    with the following one:

    location ~ / {
    index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
    try_files $uri $uri/ /index.php?$args;
    }
  3. In file /usr/local/psa/admin/conf/templates/custom/domain/service/nginxWordpressIndexing.php replace

    location ~* "^<?php echo $OPT['ssl'] ? $wordpress->httpsLocation : $wordpress->httpLocation; ?>" {

    with

    location ~* ^/<?php echo $wordpress->location; ?> {
  4. Re-create web-server configuration files:

    # /usr/local/psa/admin/bin/httpdmng --reconfigure-all

Have more questions? Submit a request
Please sign in to leave a comment.