WordPress Skeleton, VVV, Multisite and the Right Nginx Rules

I am creating an automatic WordPress deployment using Composer and saving the wp-content folder outside the main WP installation (because I have some custom plugins and themes) that are pulled from github.

After pulling out of github and a working composer, my folder structure looks like this:

-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 use VVV as a development environment and VVV uses nginx, so my rewrite rules do not work.

VVV uses 2 conf files: one file shared by all sites in the virtual machine (general rules) and one file for each site (basically just lists the root directory).

Here is my conf config 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;

( , CSS JS), :

1) CSS. Chrome index.php:

Uncaught SyntaxError: Unexpected token <

note - , , Twenty Fifteen , .

2) , - , http://auto.dev/wp-admin/network/, : http://http//auto.dev/wp-admin/network/ , ,

3) , . Stuff http://auto.dev/wiki/wp-admin/

4) , , , .

+4
1

:

wp-content/ wp/, :

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

, Twenty Fifteen, /wp/wp-content/, , .

/wp/ URL- , Daniel Bachhuber gist snippet, . network_site_url, .

<?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 );

. # 23221 Multisite

GitHub nginx + multisite wp- ( ).

+3

Source: https://habr.com/ru/post/1622755/


All Articles