4

I am building an automated WordPress deploy using Composer, and am keeping the wp-content folder outside of the main WP install (because I have some custom plugins and themes) which is pulled from github.

After pulling from github and running composer, my folder structure looks like:

-composer.php
-env.php
-public/
 |-index.php
 |-wp-config.php
 |-wp-content/
   |-themes/
   |-plugins/
   |-sunrise.php
 |-wp/
   |wordpress stuff

My htaccess rules work well when using MAMP, but I am using VVV as my development environment and VVV uses nginx, so my rewrite rules don't work.

VVV uses 2 conf files: one file thats shared by all sites on the VM (common rules) and one file for each site (basically just lists the root dir).

Here is my site specific conf file:

server {
    listen       80;

    listen       443 ssl;

    server_name  auto.dev ~^auto\.\d+\.\d+\.\d+\.\d+\.xip\.io$;
    root         /srv/www/auto/htdocs/wordpress;

    # my rules    
    # tells nginx to prepend "wp" to things
    rewrite ^/(wp-.*.php)$ /wp/$1 last;
    rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
    # end WP dir rules 

    include /etc/nginx/nginx-wp-common.conf;

}

so I added

rewrite ^/(wp-.*.php)$ /wp/$1 last;
rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;

And that kind of works (I am able to get the the admin area, and the admin area has all of its CSS and JS), but I am facing 3 big problems:

1)The frontend of the site no longer has its CSS. Chrome's console shows an error on the second line of my index.php:

Uncaught SyntaxError: Unexpected token <

note - It looks like SOME of the themes work, a site with the Twenty Fifteen theme looks like it works.

2) I cannot get to the multisite network area, for whatever reason anytime I attempt to goto http://auto.dev/wp-admin/network/ my request is rewritten as: http://http//auto.dev/wp-admin/network/and thus obviously doesn't work

3) Finally I cannot login to my subsites. Stuff like http://auto.dev/wiki/wp-admin/ gives me a redirect loop

4) I just noticed that when I try to change the theme for a site, the theme previews are broken.

rugbert
  • 11,603
  • 9
  • 39
  • 68
  • try disabling multisite and getting it to work then re-enable it. – Joshua Jan 07 '16 at 05:05
  • I'm not an nginx guy so I'm not much help but you might want to check out https://roots.io/trellis next time you do something like this. It runs an ansible playbook to run/deploy a highly optimized Vagrant instance similar to VVV, which helps avoid a lot of what you are going through. – serraosays Jan 07 '16 at 06:09
  • I know this is controversial, but I think you're going down the wrong path with VVV. If you need an environment, i.e. for development, then why not just use a full blown clone of your production in every way? I use a .net domain that is a full clone, or I use an AWS instance for disposable stuff like allowing outsources to work on stuff in a low security low value environment. This doesn't answer your question, but it took me months to learn to spin up a GUI in the cloud for WP [Codeception, Selenium, Con. Int., Git ect.], but it was worth it. Forget VVV, & go full clone + your dev tools. – Jim Maguire Jan 07 '16 at 15:59
  • The redirect loop is probably related to the wordpress db records versus whats in the config.php file and not necessarily the nginx rules. – Shawn Jan 08 '16 at 00:50

2 Answers2

5

Just few notes:

Your wp-content/ folder isn't under the wp/ folder as you stated here:

rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;

Since default themes, like Twenty Fifteen come shipped with the /wp/wp-content/ folder, it could explain why you get it to work there.

Regarding the missing /wp/ part in the network admin urls, Daniel Bachhuber has posted this handy gist snippet that fixes that problem. It uses the network_site_url filter to inject it.

<?php
/**
 * Fix network admin URL to include the "/wp/" base
 * 
 * @see https://core.trac.wordpress.org/ticket/23221
 */
add_filter( 'network_site_url', function( $url, $path, $scheme ){
    $urls_to_fix = array(
        '/wp-admin/network/',
        '/wp-login.php',
        '/wp-activate.php',
        '/wp-signup.php',
        );
    foreach( $urls_to_fix as $maybe_fix_url ) {
        $fixed_wp_url = '/wp' . $maybe_fix_url;
        if ( false !== stripos( $url, $maybe_fix_url )
            && false === stripos( $url, $fixed_wp_url ) ) {
            $url = str_replace( $maybe_fix_url, $fixed_wp_url, $url );
        }
    }
    return $url;
}, 10, 3 );

Also see the open ticket #23221 on Multisite in subdirectory with root site address

Some discussions here on GitHub regarding nginx + multisite with wp-skeleton structure (I posted there some experiments some time ago).

birgire
  • 11,258
  • 1
  • 31
  • 54
0

Consider a solution just with updated NGINX config, which I've published on github. Change your rewrites with following

if (!-e $request_filename) {
   rewrite ^/(wp-admin/.*)$ /wp/$1 last;
   rewrite ^/[_0-9a-zA-Z-]+(/wp-admin/.*)$ /wp/$1 last;

   rewrite /wp-admin$ $scheme://$host$uri/ permanent;

   rewrite ^/[_0-9a-zA-Z-]+(/wp-includes/.*) /wp/$1 last;
   rewrite ^/(wp-[^/]+\.php)$ /wp/$1 last;
   rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
   rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
rewrite ^/(wp-includes/.*)$ /wp/$1 last;

That will solve all the problems with access to admin panels and the network admin panel with sub-folder installation of the Wordpress Multisite. No need code writing.

Paul Burilichev
  • 406
  • 3
  • 10