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
58 comments
Hello @DoSieci,
Your case requires the additional investigation.
Please, submit a ticket to Plesk support, this will let us have a closer look at the issue.
Plesk team,
Can you please add instructions for Obsidian also?
Thank you!
Hi Oleg Burca,
I just run the solution on our test servers and the same applies for Onyx and Obsidian. Make sure that you are replacing the entire block:
<?php if ($VAR->domain->physicalHosting->directoryIndex): ?>
location ~ /$ {
index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
}
<?php endif ?>
with
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;
}
Hi Kuzma Ivanov,
I am tried to add this code to the file /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php as explained in step 3 but in Plesk Obsidian the block of code that we need to replace is not exactly like the one you mentioned there.
In my case the block of code I can see similar to the one mentioned here is this one (start at line:155 ):
<?php if ($VAR->domain->physicalHosting->directoryIndex && !$VAR->domain->physicalHosting->proxySettings['nginxProxyMode']): ?>
location ~ /$ {
index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
}
<?php endif ?>
Could you please check it and let us know what would be the bock of code to replace for Obsidian?
Regards.
Hello @Jorge,
The following config is to be replaced on Plesk Obsidian:
<?php if ($VAR->domain->physicalHosting->directoryIndex && !$VAR->domain->physicalHosting->proxySettings['nginxProxyMode']): ?>
location ~ /$ {
index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
}
<?php endif ?>
I've successfully tested it.
The article will be updated.
Thank you @Denis Bykov
This worked for me. I run about 30 WP sites. What worked for me, was using the custom template. I used the Plesk 17.8 settings above, under "For all existing and newly created websites in Plesk Onyx & Obsidian" .
e.g.
This was the only way i could get the question mark out of the urls. For some sites the standard overrides, that you can add in "Additional nginx directives" would not work in some cases.
Note, to properly test that, you need to reset permalinks in some cases. To do that, change them to Plain, CLICK SAVE, then Change them back, and click save. Ignore the SEO warning when you do this.
Boun Vilailath, and all others having the question mark showing up still in their url, breaking pages, I wanted to say, i had the exact same issue, this resolved it for me, only after i removed the old settings that i had in the nginx/apache overrides. so be sure to remove those after you add the new directives to a custom template.
e.g. the old settings are whats pointed out in the single site directive, which did not work for me on some sites.
Notice the rewrite rule there. Thats whats adding the question mark.
You need to use the full location block directive if your having the question mark still showing up, atleast for my version of Plesk (17.8).
Note, the title of the article is decieving, i never received a 404 not found, this because the home page url was still loading, the portion after the slash, e.g. /?about was not loading, due the question mark. So no 404 ever happened. Instead as mentioned, i just saw the home page. SO they didnt 404, they just didnt work. Hence, this article threw me off at first (weeks prior), in the sea of other help articles on this, i thought it was irrelavant, however in the end i found it was. So it may help lots of other developers to update the title!!
this works, but the mail autosdiscovery is broken after this..
Hello Koray Snoray
Please, check my response at https://support.plesk.com/hc/en-us/articles/360009747280
For me, which also happened last night, this also breaks mailman. We have mailman as a subdomain. Adding the overrides in either the global config override, or the parent domain (WP Site) it breaks mailman subdomain.
Is there an override that i can maybe add to the subdomain? its kind of sad that the subdomain picks it up anyway, because this is just for this particular site on the parent domain. I guess thats the nature of how the subdomain loads.
I at first thought the mention above for "mail" was a potential resolution for me as well, but im not sure what the "mail autodiscovery" is, so im thinking thats not related.
Hello Brian,
Mail Autodiscovery is functionality that allows email clients such as Thunderbird or Outlook pick up all information about mail server automatically.
Please, take a note that we are not aware if the workaround described in the article affects Mail Autodiscovery. To assist you better on that case, please, submit request to support team and we will check Mailman issue along with any others if arise:
https://support.plesk.com/hc/en-us/articles/213608509-How-to-submit-a-request-to-Plesk-support-
I have "FPM served by Nginx" enabled on all our WordPress subscriptions and they all work. Apache rewrite rules are still working. Is this a bug?
Everywhere I look it says .htaccess won't be processed if "FPM served by Nginx" is enabled. I haven't added any Additional Nginx directives. The sites just work.
Can anyone explain this?
Hi Andy Little,
The Wordpress Toolkit extension now adds automatically some configuration on Nginx in order to make work the permalinks.
Hi Francisco Roman Garcia Rodriguez,
That would make sense, however, my Magento sites all work with FPM served by Nginx and they use htaccess rewrite rules.
Thanks
Hi Andy Little,
I could test this behavior in a test environment, and what I could deduct from it is that it's something implemented in magento2-core, as this only happens with Magento, not with a regular PHP test page.
Thanks Francisco Roman Garcia Rodriguez,
Actually, it's all our Magento sites (M1 and M2) and all our WordPress sites. They all work with FPM served with Nginx and I've not had to make any special accommodations. Literally all I did was switch to "FPM served by Nginx" in the PHP settings and that's it. They all still work. No issues with redirects as others have described.
From what I've read, this shouldn't be the case.
In the Apache and Nginx settings, Nginx is set in proxy mode. I'm not sure if this is why, but nowhere else does anyone mentioned disabling this before getting the 404 errors.
Thanks again
Hi Andy Little,
Reproduced that behavior and it's explained here: [BUG] Wordpress pages shows 404 not found error if FPM application served by nginx and Proxy Mode enabled
Hi Francisco Roman Garcia Rodriguez,
Is this the bug "PHP continues to be served by Apache when Proxy mode is enabled. The behaviour has been confirmed as Plesk bug PPPM-11234".
That would make sense and would explain why my apps all work even with "FPM served by Nginx" enabled.
I guess if I turn off Proxy Mode I will experience the same issues as the others in this thread?
Thanks
Hi Andy Little,
If you turn off Proxy mode, then the webserver won't use .htaccess rewrite rules. Then, yes, you should use the resolution from this article.
Hi Francisco Roman Garcia Rodriguez,
Great. At least I know it's due to Proxy Mode. I just wasn't sure why I wasn't getting the same error as others in this thread. Maybe the article should be updated to state this only happens if Proxy mode is disabled?
Thanks
Hi Andy Little,
Article is updated. Thanks :)
Great support. Thanks Francisco Roman Garcia Rodriguez :)
After trying many different "fixes" found on the web, this one actually worked. Thank you!!
This keeps breaking some of my websites whenever there is a new update of plesk, and this manual solution is no real solution. How can we fix this permanently ?
Francisco Roman Garcia Rodriguez, I was excited to read that there is a deeper explanation of why this happens and how to fix it. However, the URL you linked (as above) is dead now. Please, can you update the link to this bug you mention ...
For anyone else trying to gain clear insight into how nginx & apache work together in plesk-land, I found the following links useful:
Thanks in advance.
Hi Chux Uzoeto,
I don't consider necessary to recover this article since the bug PPPM-11234 was already fixed in Obsidian early versions and the workaround for that bug is the same as described here in this article https://support.plesk.com/hc/en-us/articles/213912945.
Thanks, @Francisco Garcia ... I understand.
My problem is that even the solution you linked to for Obisidian is exactly the same fix that breaks each update.
What's the use of a control panel like Plesk that one has to pay for, if after every update many of your sites are broken and you have to manually fix them.
This is a known issue that has persisted across versions of Plesk and for seemingly many years. Why is Plesk refusing to find a permanent solution for this problem? Taking consumers for granted?
This problem is making me seriously consider ditching plesk and seeking out an alternative.
Hi Chux Uzoeto,
If this issue is coming back to you on every update, I recommend you to open a support request.
This is the only way to improve our product and to find out why it still happens to you after every update.
FYI - still an issue with Plesk 18.0.45! I had to add the additional directives to get WP working properly on a domain I created last week.
Same here. This is preposterous. I had tons of websites perfectly working natively on NGINX without touching anything. As soon as I change a website into Apache and then switch into NGINX it breaks and it never works again with the 404 error.
Plesk for godsake DO something!. This is definitely broken. Why would it work perfectly fine and then break for no reason?.
Please sign in to leave a comment.