After switching a WordPress website to FPM served by nginx in Plesk, it fails to load with "404 Not Found" on all pages except start page

Follow

Comments

36 comments

  • Avatar
    Tadashi Spade

    i am new to Plesk.
    my Plesk does not showing me this menu Plesk > Domains > example.com > Apache & nginx Settings 
    please help ....

    1
    Comment actions Permalink
  • Avatar
    Lev Iurev

    @Tadashi  this menu is available only for Plesk admin

    0
    Comment actions Permalink
  • Avatar
    Jeff Carter

    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?

     

     

     

    0
    Comment actions Permalink
  • Avatar
    Robert Asilbekov

    @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.

     

    0
    Comment actions Permalink
  • Avatar
    Jeff Carter

    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?

    0
    Comment actions Permalink
  • Avatar
    Jeff Carter

    My testing shows that #2 is correct.

    0
    Comment actions Permalink
  • Avatar
    Konstantin Annikov

    @Jeff

    Yes, you are right here. 

    Thank you for the input. 

    0
    Comment actions Permalink
  • Avatar
    Jonas Klinker

    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!

    0
    Comment actions Permalink
  • Avatar
    Ion Iacob

    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.

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    @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.

    1
    Comment actions Permalink
  • Avatar
    Ion Iacob

    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.

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    @Ion Iacob

    Hi!

    In case your OS is CentOS, Apache logs are at /var/log/httpd.
    Please, consider contacting Plesk Technical Support.

    1
    Comment actions Permalink
  • Avatar
    Denis Bykov (Edited )

    @Jonas Klinker
    According to WordPress blog page, correct Nginx rewrite rules for a subdirectory multisite setup are following:

    location ~ ^(/[^/]+/)?files/(.+) {
    try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
    access_log off; log_not_found off; expires max;
    }

    location ^~ /blogs.dir {
    internal;
    alias /var/www/example.com/htdocs/wp-content/blogs.dir ;
    access_log off; log_not_found off; expires max;
    }

    if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite ^(/[^/]+)?(/wp-.*) $2 last;
    rewrite ^(/[^/]+)?(/.*\.php) $2 last;
    }

    location / {
    try_files $uri $uri/ /index.php?$args ;
    }

    location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass php;
    }


    Refer to the following page for more information: https://codex.wordpress.org/Nginx

    0
    Comment actions Permalink
  • Avatar
    Jonas Klinker (Edited )

    @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

    nginx: [warn] duplicate MIME type "text/html" in /var/www/vhosts/system/DOMAIN1/conf/vhost_nginx.conf:15 nginx: [warn] duplicate MIME type "text/html" in /var/www/vhosts/system/DOMAIN2/conf/vhost_nginx.conf:15 nginx: [warn] duplicate MIME type "text/html" in /var/www/vhosts/system/DOMAIN2/conf/vhost_nginx.conf:15 nginx: [emerg] no port in upstream "php" in /var/www/vhosts/system/DOMAIN2/conf/vhost_nginx.conf:25 nginx: configuration file /etc/nginx/nginx.conf test failed
    0
    Comment actions Permalink
  • Avatar
    Alexander Tsmokalyuk

    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.

    0
    Comment actions Permalink
  • Avatar
    Marcos Paulino Chahin

    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?

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov (Edited )

    @Marcos

    Hello!
    Generally, this error means that PHP handler configuration contains a syntax error.

    Please, check these articles: 1, 2

    0
    Comment actions Permalink
  • Avatar
    Unknown User

    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;
    }

    1
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    @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.

    0
    Comment actions Permalink
  • Avatar
    Peter Luit

    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?

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello @Peter, in such case you need to contact Plesk administrator and request performing the steps from this article.

    Thank you for understanding.

    0
    Comment actions Permalink
  • Avatar
    Boun Vilailath (Edited )

    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?

    0
    Comment actions Permalink
  • Avatar
    Artyom Volov

    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

    0
    Comment actions Permalink
  • Avatar
    JackLinkers (Edited )

    rewrite ^/(.*)$ /sub-directory/index.php?$1;

    rewrites WordPress URL's in subdirectory, but now throws 404 errors on static files.

    0
    Comment actions Permalink
  • Avatar
    Alexandr Redikultsev

    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.

    0
    Comment actions Permalink
  • Avatar
    Allen

    This is the HTACCESS config.

    [content of the apache configuration file has been removed]

    0
    Comment actions Permalink
  • Avatar
    Allen

    Here is the entire htaccess file

     

    [content of the htaccess file has been removed]

    0
    Comment actions Permalink
  • Avatar
    Konstantin Annikov (Edited )

    @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.

    0
    Comment actions Permalink
  • Avatar
    Arda Oğul Üçpınar

    Hell! You saved my day man! Thanks.

    1
    Comment actions Permalink
  • Avatar
    DoSieci.pl (Edited )

    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!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request