How to resolve the 404 Not Found error on all pages except the home page after switching a website to FPM served by nginx in Plesk
Symptoms
- After setting PHP for a domain as an FPM application served by Nginx in Plesk at Domains > example.com > PHP Settings, only the home page is loading in a web browser. Other pages show a “404 Not Found” error.
- The domain is using rewrite rules, which are defined in the
.htaccess
file.
Cause
When PHP is running as an 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 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:
- Log in to Plesk.
- Go to Domains > example.com > Hosting & DNS > Apache & nginx Settings.
- Add the content below to the Additional nginx directives field:
if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location|status_phpfpm)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
}
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:
rewrite ^/(.*)$ /sub-dir/index.php?$1;
-
-
Note: For WordPress multisite network based on a subfolder, add the above rule for each subdirectory.
-