• 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
  • Inviting everyone to the UX test of a new security feature in the WP Toolkit
    For WordPress site owners, threats posed by hackers are ever-present. Because of this, we are developing a new security feature for the WP Toolkit. If the topic of WordPress website security is relevant to you, we would be grateful if you could share your experience and help us test the usability of this feature. We invite you to join us for a 1-hour online session via Google Meet. Select a convenient meeting time with our friendly UX staff here.

Question how to do this on wordpress site, with nginx

larryk

Regular Pleskian
Hi,

CentOS Linux 7.2.1511 (Core)‬
Product Plesk Onyx
Version 17.0.17 Update #12, last updated on Jan 17, 2017 12:48 PM

PHP FPM served as nginx


1) root vhost has wordpress installed (as domain.com/ WP running the site)
with perma links as: post name

2) i want to create a sub folder (domain.com/sub) that has php pages, like so:
domain.com/sub/index.php
domain.com/sub/thankyou.php

3) I want the following URLS to execute the /sub/index.php:
domain.com/sub/index.php
domain.com/sub/
domain.com/sub

4) obviously, keep WP working
how can I accomplish this?

currently, I don't think it can be done?
I've tried various things, settings, configs, etc. no matter what I try,
one fix will break something else :(

so maybe I'm just doing it wrong :)

PS. I do realize I can't name a WP page "sub"
 
I think this is unspecific to Plesk, it's more a general thing with Wordpress, that nesting another website in a Wordpress installation won't work. Mostly for the reason that on the top level of a Wordpress website, .htaccess (or other rules) define rewrites. These don't only apply for the top level directory, but they apply to all subsequent directories, too. It can work as long as there is no such rewrite mechanism for the top level directory of the Wordpress installation. Else it will not work.
 
thanks, but I would not call it "another website"...

think of it this way (its all just php pages)

domain.com/sub/ = I control via rules being seen 1st and if not match... let WP get it.
domain.com/ = WP controls

The problem I see (but could be wrong) is,

in the vhost nginx.conf file, you have this and I guess this is default in plesk?
location / {
proxy_pass http://99.99.99.99:7080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Accel-Internal /internal-nginx-static-location;
access_log off;
}


And I can't edit it, because if I do... any time I save php, nginx, apache pages in the plesk, it erases my changes and/or recreates the default directives.
that and/or the including of vhost_nginx is at the bottom

I'm not very good/smart at doing this stuff, but would appreciate it, if there is something I could try?
I don't need any htaccess file (unless it is required to make it work).

thanks
 
this is my goal, see OP:

these are working:

this happens by default (all nginx) - PROXY MODE is OFF, no htaccess files

domain.com/test-page/ = wordpress perm link (POST NAME)
domain.com/ = wordpress home page
domain.com/sub/index.php = my own subfolder and custom php page


the 2 urls below are the issue:

domain.com/sub/ = wordpress sees page not found (needs to go to sub/index.php)
domain.com/sub = wordpress sees page not found (needs to go to sub/index.php)


is there not a way to fix the 2 issues WITHOUT breaking the 'working' urls?
 
The right place to set additional Nginx directives is:
GUI > Subscriptions > your subscription > Websites & Domains > Apache & nginx settings
Directives entered into the Nginx settings box will not be overwritten by server reconfigurations.

Contentwise I do not understand what exactly is the issue. I think what you want is to set a default directory page for the /sub directory. Maybe this page will help, section "Multiple index directives": https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
 
Thanks Peter...

:) I've seen that pitfall page before... but today, I can read it an "understand" more of it :) YEAH I'm learning!!!


I've not done a good job of explaining what I'm trying to do with OP. Let me try again:

a) I have WP installed at the root of a domain and all is good, working great with permalinks (set as POST NAME).
b) I also need to execute my own PHP pages on this same domain and I'm putting them in a sub folder (domain.com/subfolder/)

Here are two problems I have with item B:
1) the only way I can access the php files in the subfolder is full path and page name (domain.com/subfolder/index.php)
2) I also can't access the index file via these 2 urls: domain.com/subfolder/, or domain.com/subfolder

under apache, the above worked fine, as expected.
under nginx + apache, the 2 problems are causing my client issues. People say, the "page doesn't exist"

thanks
 
so here is another description of my problem:
http://community.rtcamp.com/t/accessing-non-wordpress-directory-in-website-root/1009/5

my thoughts:
1) because of defaults and that I don't want to 'over ride" plesk's control of nginx.conf file --- it doesn't appear I can do what I want to do.
2) one solution is to install WP in a sub directory (not the root) and this might be the only solution?

however, both can, might, or be a problem in the future = I don't want to create any future problems :)
 
Hello,

Maybe I can be of some help.

Firstly, because you are using nginx, .htaccess does not apply to you regarding rewrites. All of your rewrites will be done in the "Additional Nginx Configuration" area that Peter specified. You'll need to add at least the following rules to this config to have a working WP site:

Code:
location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        
       location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                 include /etc/nginx/fastcgi.conf;
                 fastcgi_intercept_errors on;
                 fastcgi_pass "unix:///var/www/vhosts/system/[yourdomain.com]/php-fpm.sock";
       }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}

Furthermore, because these rules indicate how to process php files regardless of their location, your subdirectories SHOULD work once nginx has been configured correctly.

If you're looking to create a sub WP site altogether, perhaps you should try adding a subdomain to your original domain and specify the document root to be at the sub directory you're working with. Then you can install WP at that site level and likely run into fewer problems. You'll still need the above rules in your nginx conf regardless.

Take a look here for more tips including how to make your WP site more secure: https://codex.wordpress.org/Nginx
 
Lastly, so that you fully understand how Plesk works:

The above config file is actually stored in its entirety at:
/var/www/vhosts/system/[yourdomain.com]/conf/vhost_nginx.conf

and you can modify this file ONLY to your heart's desire. It will be automatically included in your nginx.conf.

To be very clear though, this file is included WITHIN a server block of your nginx.conf, meaning that certain directives and blocks won't be allowed here. These include especially map and upstream directives. There are other ways to include these again if absolutely necessary, but you shouldn't need them unless your site gets more complex. You may also be interested in converting to WP multisite, which is another beast in itself.

/var/www/vhosts/system/[yourdomain.com]/conf/vhost.conf and /var/www/vhosts/system/[yourdomain.com]/conf/vhost_nginx.conf include any necessary Apache directives you may need to add, but they won't affect how your php is processed or your rewrites because your site is processed first by nginx then second by Apache. Nginx handles the php rendering and Apache simply serves the files.
 
thanks for the links, ideas, tips, etc.

here are some issues/problems?
1) a 'valid' example or legit reason to solve this problem is a 'staging blog'

example: domain.com = root is live WP install
domain.com/stage/ = a copy of the root install, so you can test

NOTE: using a sub domain or another website is NOT the same thing as the live site. so I want an exact copy, including SSL, etc.
i realize /stage/ is one level deep, but that difference SHOULD be handled by redirect or the DB field (as opposed to a different url all together)

2) I understand vhost_nginx.conf can be used, but you obviously can't use locations that plesk already used... which from what I can tell IS THE MAIN problem.

3) the order of reading/processing the conf file.... if I could add my own custom nginx conf file ABOVE / before the the default... i believe the problem would go away.

PS.
my OP of just a sub directory -- I just moved it into WP and the issue is gone :)
however, surely OTHER PEOPLE have wanted a staging blog or copy of the blog in a sub directory --- did you get it to work?

PSS. this is what I have for the vhost_nginx.conf, which kind of works (if you use full paths), but the home page does not

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

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

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

if I went with subdomain, maybe I will not have issues? I guess after all... the root domain is "set" in the database... its just used as a variable... right?
o_O:confused:
 
yes :)

so I created the sub domain and installed WP there. FYI. I do use duplicator and like it.
all works as expected...

at first, I was thinking a sub.domain.com would not = dommain.com, but at end of day... its just a variable.

thanks
 
Back
Top