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
60 comments
i am new to Plesk.
my Plesk does not showing me this menu Plesk > Domains > example.com > Apache & nginx Settings
please help ....
@Tadashi this menu is available only for Plesk admin
My nginx config analysis warns that the prescribed replacement:
location ~ / {
index index.php index.cgi index.pl index.html index.xhtml index.htm index.shtml;
try_files $uri $uri/ /index.php?$args;
}
Does not have an ideal regex pattern.....
"Regex location has no regex pattern
Regex location has a valid modifier, but does not have a regex pattern.
Performance-wise it is more efficient to configure exact or prefix matching for locations that do not require regex matching. It is also less prone to errors. Please refer to the documentation describing location directive to learn more."
"Regex location has no anchors in regex pattern
Regex location has a regex pattern without ^ or $. This is a configuration style that is prone to errors. It may also lead to a situation when requests partially matching the regex pattern are incorrectly routed to this location.
Always use ^ or $ achor in a regex pattern."
Given this advice, should that location directive be modified?
@Jeff As far as I understand analyzer does not like ~ in location. According to nginx docs "...the “~” modifier (for case-sensitive matching). To find location matching a given request, nginx first checks locations defined using the prefix strings (prefix locations)."
You may remove "~" it should not affect performance. As for other options, I see no problems. Moreover, the same sample is provided by Nginx and WordPress. However, it would be great if you may suggest a better option to build an ideal regex.
Yes, my question really boils down to which new configuration the article should advise:
1. location / {
(Which essentially removes the regex)
or
2. location ~ /$ {
(Which correctly anchors the general regex pattern)
It does seem that the WordPress Codex recommends #1. Is there agreement then?
My testing shows that #2 is correct.
@Jeff
Yes, you are right here.
Thank you for the input.
How can I add the rule for each subdirectory for wordpress multiside?
i.e.: domain is "example.de" and there should be a second wordpress installation in "example.de/test", how can I add the rule to this domain while having "example.de" still working?
When I add the rule for ../test to the nginx-settings for example.de like:
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
rewrite ^/(.*)$ /test/index.php?$1;
}
It will work on subdomain, but the main domain isnt working anymore..
Thanks for your help!
My sites with wordpress give error 500. Where and how can we see the error? Only when I delete all the themes of the wordpress allows me to access wp-login.php, but when installing a theme the site breaks again.
@Ion Iacob
Hello!
There is a possibility that some plugin or theme contains error and provokes such issue.
Here is the article for troubleshooting error 500: [HUB] error 500.
In case the investigation from our side is required, contact Plesk Technical Support.
I'm running the compando # ls /var/log/ and I can not find the apache folder.
I have 2 subscriptions in plesk. One works with wordpress perfectly. The other one has stopped working, but if I install wordpress again it works for a few hours, then again it gives 500 error to the web page.
@Ion Iacob
Hi!
In case your OS is CentOS, Apache logs are at /var/log/httpd.
Please, consider contacting Plesk Technical Support.
@Jonas Klinker
According to WordPress blog page, correct Nginx rewrite rules for a subdirectory multisite setup are following:
Refer to the following page for more information: https://codex.wordpress.org/Nginx
@Denis Bykov
Thanks for your help! I have to change "example.com" and "blog.dir", right?
No matter, I got an error when setting on domain -> Additional nginx directives field in Plesk at Domains > example.com > Apache & nginx Settings
Jonas,
Please make sure you haven't specified "text/html" type in Additional nginx directives. This type is included by default and should not be specified explicitly.
On both a new and old plesk onyx server using web host, we get this:
Error: phpinimng failed: Unable to update the config file for 'fpm' service due to syntax errors.
When we add the directives to a single website. Any ideas why?
@Marcos
Hello!
Generally, this error means that PHP handler configuration contains a syntax error.
Please, check these articles: 1, 2.
This directive breaks the wordpress WP Rocket cache plugin. Caching doesn't work for all pages except homepage.
If I use another directive below - WP rocket works correctly:
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
@Marcin, thank you for letting us know about the issue.
To resolve the issue with Nginx configuration compatibility with WP Rocket, consider contacting WP Rocket Support.
Well, since I am not the admin on the highest level in Plesk, I cannot modify any settings to make a WordPres site run under Nginx. Is there any other way to do this?
Hello @Peter, in such case you need to contact Plesk administrator and request performing the steps from this article.
Thank you for understanding.
My urls work fine when I choose plain permalinks where it shows my page url by ID. But this url structure is not desirable.
This problem is happening to me when I install WordPress on a subdomain. Why is it that all my subpage URLs have to have a "?" in front for it to work after I insert ngix code. For example, mydomain.com/?about. How do I get rid of the "?" before my page name in the URL?
Hello @Boun Vilailath,
This is expected the behavior of default Plain permalinks in WordPress.
If it is required that Permalinks display ID without questions mark, I suggest using Custom Structure for Permalinks.
To do that:
1. WordPress Dashboard > Settings > Permalinks.
2. Select Custom Structure.
3. Select "/%post_id%/".
4. Click Save Changes.
where you can select "/%post_id%/".
In this case, URL will be displayed without the mark:
example.com/wordpress/1/#comments
rewrite ^/(.*)$ /sub-directory/index.php?$1;
rewrites WordPress URL's in subdirectory, but now throws 404 errors on static files.
Hi @JackLinkers,
You should use try_files or if if (!-e $request_filename) in order to process static files without rewriting anything to avoid getting 404 errors.
This is the HTACCESS config.
[content of the apache configuration file has been removed]
Here is the entire htaccess file
[content of the htaccess file has been removed]
@Allen
Could you please clarify your question? Am I right that htaccess files are not working for the website?
If so, please check that php is being processed by Apache under Plesk > Domains > example.com > PHP Settings .
In case the handler has been switched to 'FPM served by nginx', htaccess files are ignored. This is how nginx works.
Hell! You saved my day man! Thanks.
its doesnt work...after rebuild pages still show 404 on wordpress pages. also i have this custom template before and it stop working after upgrade plesk!
Please sign in to leave a comment.