• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved nginx + wordpress (plesk default config issue?)

larryk

Regular Pleskian
Hello, something is odd to me and I don't know enough, other than asking a good question :)


1) default install of nginx and all is good. installed WP at root of domain.
2) FPM via nginx is selected
3) the blog is installed and it has NO htaccess file

4) here is my findings and odd thing, plus question:

a) IF I HAVE THIS in the apache & nginx 'additional directives' == the blog works fine and the permalinks work too :)

if (!-f $request_filename){
set $rule_1 1$rule_1;
}
if (!-d $request_filename){
set $rule_1 2$rule_1;
}
if ($rule_1 = "21"){

rewrite ^/wp-admin/(.*)\.php$ /wp-admin/$1.php last;
rewrite /. /index.php last;

}


B) however, "if statements" are not optimal for nginx, not supposed to use them...so this is supposed to work and be better, right?

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


but when you do that, you get this error -- "location /" has already been defined
== that is because the initial config/setup that default plesk did, used the / location ==
FYI> that is over my head... I just know that is the issue, meaning, plesk set it up
and already defined lcoation / --- ie. that is why the error says its duplicated.

SO, I try this:

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

BUT back to the 404 not found for permalinks :(

what is the solution?

thanks for your help!!!


ps. reference: http://nginxlibrary.com/wordpress-permalinks/
 
follow up

great simple info...
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/


SO I tried this:
only this one line (no location needed)
try_files $uri $uri/ /index.php;


but when going to permalink page,
i get 404 not found with this in the error log:
19794#0: *10867 "/var/www/vhosts/domain.com/httpdocs/page-name/index.html" is not found (2: No such file or directory)

WHO or WHAT or WHERE is that "index.html" coming from????
what put that there?

exactly, page-name/index.html DOES NOT exist! I know :)

I don't understand how "try_files $uri $uri/ /index.php;" tells it to put a index.html on the end?
 
so interesting????
https://kb.plesk.com/en/126908

IMO, there are problems wih that solution:
1) if is evil = so says nginx
2) that page says: Note that any changes made in default configuration templates will be lost after installation of Plesk microupdates.

thoughts?
 
whether if is evil or not, on nginx setup, only this one in additional nginx directives worked for me:
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
 
thanks bulent, but your suggestion doesn't work for me :(
however, my original 'similar' does:

if (!-f $request_filename){
set $rule_1 1$rule_1;
}
if (!-d $request_filename){
set $rule_1 2$rule_1;
}
if ($rule_1 = "21"){

rewrite ^/wp-admin/(.*)\.php$ /wp-admin/$1.php last;
rewrite /. /index.php last;

}

SO the above works for one WP site/domain.

I have another site with WP installed in subdirectory and the following DOES NOT work :(
it gives the 404 error on the permalink url (testing out a page)


location /blog/ {
if (!-f $request_filename){
set $rule_1 1$rule_1;
}
if (!-d $request_filename){
set $rule_1 2$rule_1;
}
if ($rule_1 = "21"){

rewrite ^/blog/wp-admin/(.*)\.php$ /blog/wp-admin/$1.php last;
rewrite /blog/. /blog/index.php last;

}
}


ODDLY or WEIRD enough...
with the above directive AND me goign to domain.com/blog/wp-admin/ = THAT WORKS?

argh!?!?!?!?!?!? how does going to the wp-admin page work, but not a post page?


so frustrating...
if someone knew this stuff and could quickly/efficiently help me get my sites working on nginx, i would pay you
 
Hi larryk,

please, please, please.... don't leave us with missing informations... If you need help ( especially for additional NGINX directives ), always remember to POST the corresponding ".htaccess" - file, so that people willing to help you, have something to work with.
Your constant posts after posts will not really help people, who are willing to help you, because you confuse/frustrate them with additional, unnecessary text and questions, which even don't include facts and configurations and last but not least, not even depending log - entries.

If you insist of writing unnecessary text and questions in your posts, consider at least to put your CODE into CODE - brackets. ( 4. menu - item from the right, at the top of EACH editor - textbox here in the forum. :rolleyes: ).


I really wonder, why you make it so complicated, here you go with a STANDARD configuration, for ALL SINGLE - WORDPRESS - SITES ( installed in sub-directories with the name "blog" ):

Code:
    location /blog {
        index index.html index.htm index.php;
        try_files $uri $uri/ /blog/index.php?$args;
    }

Pls. consider to READ and follow suggestions from official wordpress - sites, as for example: => https://codex.wordpress.org/Nginx


If you need help with further, additional nginx directives, it is ESSENTIAL, that you post the content of the corresponding ".htaccess" - file. ;)
 
THanks....

here are my facts:

1) no htaccess files are used (i renamed them .htaccess2222) . no htaccess file in the root, nor the /blog directory.

2) this does not work
location /blog { index index.html index.htm index.php; try_files $uri $uri/ /blog/index.php?$args; }

the error is
19794#0: *10867 "/var/www/vhosts/domain.com/httpdocs/page-name/index.html" is not found (2: No such file or directory)

3) i have read many pages, many official pages from nginx sites and I'm wondering why the obvious does not work.

4) i'm trying my hardest and best to get solutions as fast as I can. I have been struggling with nginx for over a month. I'm sorry my post formatting has issues. I will work on them.

5) i'm not a SSH guy, i'm only using the plesk interface. So if you need other details, please tell me what info you need from the plesk interface

I appreciate your help.

thanks
larry
 
Hi larryk,

are you actually using "blog", while your sub-directory is "bird-hunting" ? If your are curious, why I know this sub-directory - name, it's because you pasted it in your post as link. :rolleyes:

You certainly have to use here:
Code:
    location /bird-hunting {
        index index.html index.htm index.php;
        try_files $uri $uri/ /bird-hunting/index.php?$args;
    }

In addition, would you pls. add WHICH PHP - handler you use for the specific domain? ... and pls. post all you configuration files from that specific domain, which are located at: "/var/www/vhosts/system/YOUR-DOMAIN.COM/conf/" ( you are able to add them as attachment in a *.zip - file for example in your next post ).

Pls. note as well, that worpress has as well settings for "permalinks" - pls. consider to inform us about the current setting at your wordpress instance!
You could as well inform yourself here: => https://codex.wordpress.org/Using_Permalinks

Could you pls. explain, WHO told you to RENAME the ".htaccess" - file? It would be helpfull, when you RENAME it back and inform us about the content. :rolleyes:
Consider to inform us about your current webserver - configurations at "Home > Subscriptions > YOUR-DOMAIN.COM > Apache & nginx Settings" ( consider to make some screenshots, because this is easier, than to list all the settings manually in a forum post ).

Pls. be informed, that some plugins NEED additional rewrites and depending to your webserver - configuration for that (sub)domain, you will either have ONLY a ".htaccess" - file and ( possible ) additional NGINX directives.
 
Last edited by a moderator:
Sorry for the delay in replying,

you said:
are you actually using "blog", while your sub-directory is "bird-hunting" ? If your are curious, why I know this sub-directory - name, it's because you pasted it in your post as link. :rolleyes:

answer:
no, the bird hunting is:
A) a page name
B) that is a different site
c) this thread is about a WP installed in /domain.com/blog


you asked which php handler:
FPM application served by nginx

you asked:
what WP permalink setting = post name

you asked:
and pls. post all you configuration files from that specific domain, which are located at: "/var/www/vhosts/system/YOUR-DOMAIN.COM/conf/" ( you are able to add them as attachment in a *.zip - file for example in your next post ).

I'm unaware of how I get those files from the plesk control panel. I mentioned I'm not an SSH guy. I choose not to login the server. I can ftp, but I do that at the domain level.
For this domain, my support did this...in the conf file? I think? its over my head
location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
alias /var/www/vhosts/domain.com/web_users/$1/$2;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:///var/www/vhosts/system/domain.com/php-fpm.sock";
include /etc/nginx/fastcgi.conf; }

NOTE: that came from the same domain when I had this issue:
https://talk.plesk.com/threads/a-file-with-no-extension-will-not-parse-as-php.340304/



I renamed the htaccess files, as I was making the config SIMPLE. I was removing variables. That is a good thing.
but the /blog/htaccess file had the default WP permalink script.
I had some other code in the htaccess at domain root, but again... i just removed the htaccess completely as its not part of the domain.com/blog issue.
Am I wrong?


The apache & nginx settings page has:
- all defaults.
- the ONLY 2 items checked, is proxy mode and smart static files processing
- and this in the additional directives section:

location ^~ /resort/ {
try_files $uri $uri/ /resort.php;
}

location ^~ /for-sale/ {
try_files $uri $uri/ /for-sale.php;
}

location ^~ /buy/ {
try_files $uri $uri/ /buy.php;
}

location ^~ /for-rent/ {
try_files $uri $uri/ /for-rent.php;
}

location ^~ /timeshare-resale/ {
try_files $uri $uri/ /timeshare-resale.php;
}

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


WHile I understand that some plugins may need this or that, I'm trying to get nginx to just display the permalink page OR at least stop telling me that the permalink does not exist and adding a .html to the end.

Looking forward to your reply.
thanks
 
Hi larryk,

I'm unaware of how I get those files from the plesk control panel. I mentioned I'm not an SSH guy. I choose not to login the server. I can ftp, but I do that at the domain level.
Well, now you learn something new then ( depending to your used operating system on your computer. Let's assume, that you use WINDOWS on your computer, then I could recommend to use "WinSCP" ( a SFTP client, FTP client, WebDAV client and SCP client for windows. => https://winscp.net/eng/download.php ) for example, with which you are able to login as user "root" on your server, just like you would normally login as "domain-system-user". The difference is, that you are not only able to see ALL folder and files on your server, you can even edit them directly with the built-in text - editor.
Why do I recommend this software? Well, it's hard to hear/read, but as a LINUX - system administrator, you sometimes HAVE TO learn new things and you should be aware, that Plesk can help you to administrate your server, but it will never replace a ( human ) linux system administrator, who sometimes has to configure/edit/modify/read configuration files and settings, or/and sometimes has to edit folders/files on your server, which are not available for a "domain-system-user". ;) Your description is "nice", but not based on facts and the facts are in this case the configuration files and not some "guessings" ( as far that I remember, or what ever else... ).

The above brings me now back to:
I renamed the htaccess files, as I was making the config SIMPLE. I was removing variables. That is a good thing.
??? You don't seem to understand the BASICS of the required rewrite rules at your wordpress installation and you miss the fact, that you use the combination APACHE+NGINX+PHP-FPM. You misconfigured your wordpress - installation by renaming the ".htaccess" - file, so that an essential part of your wordpress - installation is missing now. You even removed other ".htaccess" - files as well. What might be "a good thing" as you stated, is absolutely incomprehensible, because you won't be able to drive a car, if you take off the steering wheel. :rolleyes: ( ... and pls. don't reply, that it would be still possible, if... blablabla... o_O ... you know exactly what this example should imply. )

Am I wrong?
Yes, you are!

( sorry if the lines might offend or attack you - it is not meant evil, but simply mirrors my horror, about the previous steps of yours to solve the issue :rolleyes:o_O:rolleyes: )



I'm looking forward to the requested informations ( FACTS ) from my previous post for further suggestions/solutions, how you would solve your current issue and I will do my very best to leave out further ( possible ) aggresive answers/discussions, because it will only waste your time ( and mine as well ) :)

In addition, pls. note, that the prefix "INPUT" for the thread is a wrong choice. This thread and it's content has to be categorized as "ISSUE" or "QUESTION".
 
thanks...

I was able to sftp into server. The saw the location in the /system/domain/ but the files were blank, empty, or not there...
maybe nothing is there because, its truly blank/empty/not there OR I did something wrong.

apache+nginx+php-fpm, yes I'm "slowly" learning that nginx might not use htacess, but in this plesk environment, it still matters :(

NOTE: everywhere I saw said, "nginx doesn't use htacess" and I'm running nginx. SO for beginners at nginx, you can easily see where we go wrong :(

( sorry if the lines might offend or attack you - it is not meant evil, but simply mirrors my horror, about the previous steps of yours to solve the issue :rolleyes:o_O:rolleyes: )
well, I just want my stuff to work... I'm pretty sure you can help :)


but to the good stuff:
My support team got the solution for me ( in the additional directives)

# if filename doesn't exist, take the request and pass to wordpress as a parameter
if (!-e $request_filename) {
rewrite ^/blog/(.+)$ /blog/index.php?q=$1 last;
}

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

# Add trailing slash to */wp-admin requests.
rewrite /blog/wp-admin$ $scheme://$host$uri/ permanent;

technically, I was very, very close, in all my variations of testing, but had wrong understanding of nginx location block


thanks for help!
 
This directives together worked liked a charm for me:

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

if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
 
Back
Top