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 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:
-
Go to Domains > example.com > Hosting & DNS > Apache & nginx Settings.
-
Add the content below to the Additional nginx directives field:
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|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:
CONFIG_TEXT: rewrite ^/(.*)$ /sub-dir/index.php?$1;
Note: For WordPress multisite network based on subfolder, add the above rule for each subdirectory.
-
-
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.phpNote: 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 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;
} -
-
Regenerate web-server configuration files:
# plesk repair web -y
Comments
1 comment
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 :-)
Please sign in to leave a comment.