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
Apply one of the following solutions:
Log in to Plesk and add the content below to the Additional nginx directives field of the WordPress domain at Domains > example.com > Apache & nginx Settings:
if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|external-nginx-static-location)) {
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 subfolder, add the above rule for each subdirectory.
-
-
If you are in Power User view, switch to Service Provider view at Tools & Settings > Interface Management.
-
Add the rewrite rules below to the Additional nginx directives field at Service Plans > service_plan > Web Server tab:
if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|external-nginx-static-location)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
} -
Click Update & Sync to apply the changes.
-
Connect to the Plesk server via SSH.
-
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.
-
Open the file
/usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
in any text editor (for example, with the “vi” text editor) and replace the section:-
on Plesk Onyx 17.5, 17.8:
<?php if ($VAR->domain->physicalHosting->directoryIndex): ?>
location ~ /$ {
index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
}
<?php endif ?> -
on Plesk Obsidian:
<?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:
location ~ / {
index index.php index.cgi… -