Articles in this section

After switching a website to FPM served by nginx in Plesk, it fails to load with "404 Not Found" on all pages except start page

Plesk for Linux kb: technical ABT: Group A FR:PPM-1997

Applicable to:

  • Plesk for Linux

Symptoms

  • After setting PHP for a domain as FPM application served by nginx in Plesk at Domains > example.com > PHP Settings, only start page is loading in a web-browser. Other pages show "404 Not Found" error.

  • The domain is using rewrite rules, which are defined in the .htaccess file.

Cause

When PHP is running as FPM application served by nginx, PHP files are processed by nginx which does not use .htaccess files like Apache does. 

This issue has been addressed in Plesk Obsidian 18.0.34 where new WordPress installations work with PHP-FPM served by nginx.

Resolution

This issue has generally been addressed in Plesk Obsidian 18.0.34, where new WordPress installations work with PHP-FPM served by nginx.

For older WordPress installations, apply one of the following solutions:

For one domain
  1. Log in to Plesk.

  2. Go to Domains > example.com > Hosting & DNS > Apache & nginx Settings.

  3. Add the content below to the Additional nginx directives field:

    CONFIG_TEXT: if location ~ / {
    index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
    try_files $uri $uri/ /index.php$is_args$args;
    }

    • If this is a WordPress installation, which is located in a subdirectory (for example, "httpdocs/sub-dir") or this is a WordPress multisite network based on subdirectories, add the /sub-dir/ before /index.php?$1 so it will look like this:

      CONFIG_TEXT: rewrite ^/(.*)$ /sub-dir/index.php?$1;

      Note: For WordPress multisite network based on subfolder, add the above rule for each subdirectory.

For all domains
  1. Connect to the Plesk server via SSH.

  2. Create a directory for custom templates and copy default configuration templates there:

    # mkdir -p /usr/local/psa/admin/conf/templates/custom/domain

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

    Note: Any changes made in original configuration templates will be lost after an installation of Plesk micro-updates.

  3. Open the file /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php in any text editor (for example, with vi editor) and replace the section:

    • on Plesk Onyx 17.5, 17.8:

      CONFIG_TEXT: <?php if ($VAR->domain->physicalHosting->directoryIndex): ?>
      location ~ /$ {
      index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
      }
      <?php endif ?>

    • on Plesk Obsidian:

      CONFIG_TEXT: <?php if ($VAR->domain->physicalHosting->directoryIndex && !$VAR->domain->physicalHosting->proxySettings['nginxProxyMode']): ?>
      location ~ /$ {
      index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
      }
      <?php endif ?>

    with the following content:

    CONFIG_TEXT: location ~ / {
    index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
    try_files $uri $uri/ /index.php$is_args$args;
    }

  4. Regenerate web-server configuration files:

    # plesk repair web -y

Was this article helpful?

Comments

1 comment
Date Votes
  • If you don't need or use statistics, you can simplify with:

    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?$1;
    }

    A few microseconds less for each request :-)

    0

Please sign in to leave a comment.