easyengine icon indicating copy to clipboard operation
easyengine copied to clipboard

Single WordPress With SubDirectory

Open MiteshShah opened this issue 13 years ago • 31 comments

set $dir "";
if ($request_uri ~ ^/([^/]*)/.*$ ) {
      set $dir1 /$1;
}
location / {
      try_files $uri $uri/  $dir1/index.php?$args;
 }

MiteshShah avatar Jul 24 '13 15:07 MiteshShah

I have looked EVERYWHERE for an nginx config that could accomplish this. I just tested this and it works!

Thank you!

milojennings avatar Mar 13 '14 03:03 milojennings

Glad to know that it worked for you!

Welcome :)

RakshitThakker avatar Mar 13 '14 05:03 RakshitThakker

@RakshitThakker this issue will be complete when we will have subdir-wordpress site creation in easyeninge

rahul286 avatar Mar 13 '14 19:03 rahul286

Sexy.

ryanpcmcquen avatar Mar 13 '14 22:03 ryanpcmcquen

I am a little confused as this is my first experience with nginx and regular expressions. Is this the full set of directives needed in the "default" configuration file? Or is this to go inside the default server block configurations that ship with nginx installation? Your help is much appreciated.

zillionart avatar May 08 '14 13:05 zillionart

@raytara This configuration can go inside /etc/nginx/sites-available/example.com

Sample example.com: https://github.com/rtCamp/easyengine/blob/master/usr/share/easyengine/nginx/wp/basic.conf

MiteshShah avatar May 09 '14 06:05 MiteshShah

@MiteshShah I am is new at server world including nginx.

I am confused, how to use this code. Iam installing easy engine+wp+wpsc that is very easy to use and relly help me.

but I have wordpress on subdirectory so I found this topic, but I don't know how to add this code. Can you please post here complete example code placement for this config?

please edit this config files to add code above,

https://github.com/rtCamp/easyengine/blob/master/usr/share/easyengine/nginx/wp/basic.conf

Many thanks before

thenoobi avatar May 09 '14 07:05 thenoobi

@thenoobi I'm assume you are using single wordpress with nginx fastcgi cahe (--wpfc)

In this case you need to edit example.com

ee site edit example.com

Find the following line

        root /var/www/example.com/htdocs;
    index index.php index.htm index.html;

Add following codes below that line

      set $dir "";
      if ($request_uri ~ ^/([^/]*)/.*$ ) {
            set $dir1 /$1;
      }

Now find the location block

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

Chnage it

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

NOTE: I'm not tested this code with --wpfc option you need to test yourself

MiteshShah avatar May 09 '14 07:05 MiteshShah

@MiteshShah Many thanks for your instructions,

I have succesfully install wp on sub and I can access that page.


But I have another problem. custom permalink is not working now.

I am using permalinks:

/%category%/post-name.html

I get 404 when using this.

Try switch back to default permalink and working. Here my .htaccess setting:

RewriteEngine On RewriteBase /subwp/ #If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible AddDefaultCharset UTF-8 RewriteCond %{REQUEST_URI} !^._[^/]$ RewriteCond %{REQUEST_URI} !^._//._$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !._=.* RewriteCond %{HTTP:Cookie} !^._(comment_author_|wordpress_logged_in|wp-postpass_)._$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC] RewriteCond %{HTTP:Accept-Encoding} gzip RewriteCond %{HTTPS} on RewriteCond %{DOCUMENT_ROOT}/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index-https.html.gz -f RewriteRule ^(.*) "/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index-https.html.gz" [L]

RewriteCond %{REQUEST_URI} !^.[^/]$ RewriteCond %{REQUEST_URI} !^.//.$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.=.* RewriteCond %{HTTP:Cookie} !^.(comment_author|wordpress_logged_in|wp-postpass_)._$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTP:Accept-Encoding} gzip RewriteCond %{HTTPS} !on RewriteCond %{DOCUMENT_ROOT}/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index.html.gz -f RewriteRule ^(.*) "/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index.html.gz" [L]

RewriteCond %{REQUEST_URI} !^.[^/]$ RewriteCond %{REQUEST_URI} !^.//.$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.=.* RewriteCond %{HTTP:Cookie} !^.(comment_author|wordpress_logged_in|wp-postpass_)._$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTPS} on RewriteCond %{DOCUMENT_ROOT}/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index-https.html -f RewriteRule ^(.*) "/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index-https.html" [L]

RewriteCond %{REQUEST_URI} !^.[^/]$ RewriteCond %{REQUEST_URI} !^.//.$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.=.* RewriteCond %{HTTP:Cookie} !^.(comment_author|wordpress_logged_in|wp-postpass_)._$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9"]+ [NC] RewriteCond %{HTTPS} !on RewriteCond %{DOCUMENT_ROOT}/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index.html -f RewriteRule ^(.*) "/subwp/wp-content/cache/supercache/%{SERVER_NAME}/subwp/$1/index.html" [L]

NOTE: Main sites is using easy engine wordpress wpsc and running fine with all permalinks

Any missing confiig in htaccess?

thenoobi avatar May 09 '14 08:05 thenoobi

@thenoobi .htaccess not work with nginx You need to write custom rules for nginx

MiteshShah avatar May 09 '14 08:05 MiteshShah

@MiteshShah Thanks for your answer And what should I do now :(

thenoobi avatar May 09 '14 08:05 thenoobi

@thenoobi

I think you are using wrong permalink structure. The correct one is

/%category%/%postname%.html

nitun avatar May 09 '14 09:05 nitun

@nitun

yes sorry wrong type here but in wp permalinks config is still /%category%/%postname%.html

:)

@MiteshShah I am try to conver my .htaccess to nginx config using this tools http://winginx.com/en/htaccess

but I just redirected to main domain

Im trying to access domain.com/sub/catname/postname.html and get redirected to domain.com/catname/postname.html

thenoobi avatar May 09 '14 09:05 thenoobi

@thenoobi First clean your nginx fastcgi cache then test

rm -rf /var/run/nginx-cache/*

MiteshShah avatar May 09 '14 09:05 MiteshShah

Finally I'm reintalling easy engine with ee site create example.com --wpsubdom --wpfc and follow your guide, everything is working great, Many thanks for your support.

Here the right step:

  1. After install ee system, instal wp with fast cgi: ee site create example.com --wpsubdir --wpfc
  2. Add this code to server block

set $dir ""; if ($request_uri ~ ^/([^/])/.$ ) { set $dir1 /$1; } location / { try_files $uri $uri/ $dir1/index.php?$args; }

  1. rm -rf /var/run/nginx-cache/*
  2. restart nginx
  3. Finish

And now I have question, how about cache for WP sub directory? can I use wpfc like main site?

thenoobi avatar May 09 '14 14:05 thenoobi

LOL,

After my step above, example.com/wpsubdir is running great with custom permalinks, but example.com is get 404 when use /%category%/%postname%.html

thenoobi avatar May 09 '14 14:05 thenoobi

@thenoobi first this issue is for only single wordpress not for multisite.

Also in my above comment i'm said

I'm assume you are using single wordpress with nginx fastcgi cahe (--wpfc)

MiteshShah avatar May 12 '14 05:05 MiteshShah

After above changes site work on subdirectory but ee site list show site install on root ee site create domain.com -- still state site already exist. Meaning I cannot install another site again? Did something wrong? Tq

dettlee avatar Aug 18 '14 05:08 dettlee

@dettlee

ee site list is only show sites which is found on /etc/nginx/sites-enabled Also you added custom rules on example.com to make sub-directory working so ee site list not aware of this and this feature is not implemented in easyengine yet.

ee site create domain.com -- still state site already exist.

If site already exist then you can't create site you have to delete this site first or choose another domain like

ee site create hello.com

MiteshShah avatar Aug 18 '14 05:08 MiteshShah

totally aware of the subdirectory is not supported yet... just my worth of 2cents comment, when creating in subdirectory it should allow to create another subdirectory under other name tq for the good work

dettlee avatar Aug 18 '14 09:08 dettlee