Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wordpress Multisite and NGINX Configuration #39

Closed
tmort opened this issue Sep 16, 2013 · 8 comments
Closed

Wordpress Multisite and NGINX Configuration #39

tmort opened this issue Sep 16, 2013 · 8 comments

Comments

@tmort
Copy link

tmort commented Sep 16, 2013

I'm attempting to set up WordPress skeleton in a multisite configuration. WordPress skeleton already places WordPress in a subdirectory (wp by default). I've taken the following steps:

  1. git clone WordPress-Skeleton
  2. Update Submodules and checkout 3.6.1 tag
  3. Setup local-config.php to point to my local DB
  4. Install WordPress, set site settings to example.com (site), example.com/wp (WordPress URL)
  5. Configured multisite (subdirectory) and configured NGINX to serve the Multisite properly (NGINX config can be found here: https://gist.github.com/tmort/6582961)

Once all of this is configured, I can see that the main site (example.com and example.com/wp/wp-admin) both work.

I then add a new site to the network. Upon navigating to the site url (example.com/test-network-site) the front-end is broken (style.css, for example, cannot be found at the URL http://example.com/wp/test-network-site/wp-content/themes/twentythirteen/style.css?ver=2013-07-18). When navigating to the wp-admin, I'm in a redirect loop.

My end goal is to be able to use WordPress Skeleton as a base for the sites I deploy and have the multisite configuration work as it does normally (where example.com is the network main site, example.com/test-network-site is a site within the network, and example.com/test-network-site/wp-admin works as it should). At this point my main question may be is this even possible?

Unsure of how to move forward. Any insight would be greatly appreciated!

@tmort
Copy link
Author

tmort commented Oct 8, 2013

To anyone who may have a similar problem, the only solution I've found thus far is to put WordPress in the root directory, taking it out of the wp subfolder (which causes problems using WordPress Skeleton for updates, etc).

I've narrowed it down to an NGINX config issue, just haven't solved it. Will post it here if I find something.

@birgire
Copy link

birgire commented Nov 2, 2013

Here is what seems to work on my subdirectory multisite test install::

My directory structure is:

/
  content/
  wp/
  index.php
  wp-config.php

If you use for example the NginX rules proposed in the Codex, then you can try to replace this snippet:

# Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

with:

# Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) /wp$1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ /wp$1 last;
}

Then after

nginx -t && service nginx reload

I can access urls like before:

www.example.com/wp-admin/
www.example.com/site1/wp-admin/
www.example.com/site2/wp-admin/
www.example.com/site1/wp-admin/edit.php
www.example.com/site2/wp-admin/edit.php

without the /wp/ part in the url.

The /wp/ part will not work on the sub sites:

 www.example.com/site2/wp/wp-admin/
 www.example.com/site2/wp/wp-admin/edit.php

but it will work on the main site:

www.example.com/wp/wp-admin/
www.example.com/wp/wp-admin/edit.php

I've only applied this on my test setup so I will have to play with it some more before trying this out in the real world ;-)

@blueprintmrk
Copy link

Awesome I really wish we connect varnish and keep SPDY

@coreyp
Copy link

coreyp commented Nov 17, 2013

Had an issue accessing network admin menus. The above helped, as did this… open bug on WP core:

http://wordpress.org/support/topic/network-admin-menu-links-broken-on-35-subdomain-multisite-install-subfolder?replies=7

Relevant section:

"- edit wp-includes/link-template.php func network_admin_url(), edit the line"

$url = network_site_url('yourfolder/wp-admin/network/', $scheme);

Navigation between network admin pages and subsites and subsite admin pages all works as expected after making that change to core… if you dare. (I forked the WP submodule for now, which works just fine as a minor tweak to the default skeleton setup.)

@kjprince
Copy link

Had the same problems as above with rewrites, subdomain install and domain mapping.

I did the following:

  1. Dropped sunrise.php in /content
  2. Used the hack above and edited network_site_url in the link-templates.php file

Looks good so far.

So this may help anyone thats interested:

https://core.trac.wordpress.org/ticket/19796

Also related

https://core.trac.wordpress.org/ticket/23221

@zanematthew
Copy link

Hi, I've been using WP Skelton with Apache, for several years now. Recently decided to give nginx a try, and of course wanted to use WP Skelton. Thus far I'm stumped with the same issue as the original poster;

  1. http://example.com/wp-admin/ (inifinite redirect loop)
  2. http://example.com/wp/wp-admin/ (no CSS/JS)

Note, the following URLs do work:

I should be able to access the primary site as http://example.com/wp-admin/, and not http://example.com/wp/wp-admin/ (with no CSS/JS).

Can anyone point me in the right direction with the below nginx config? Note I am entirely new to ngnix, so any explanation would be greatly appreciated.

server {
    # also use www here
    server_name example.com;

    rewrite_log on;

    access_log /var/www/logs/access.log;
    error_log /var/www/logs/error.log;

    root /var/www/public/;
    index index.php;

    # Cache
    set $skip_cache 0;

    # POST requests and urls with a query string should always go to PHP
    if ($request_method = POST) {
        set $skip_cache 1;
    }   
    if ($query_string != "") {
       set $skip_cache 1;
    }   

    # Don’t cache uris containing the following segments
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
        set $skip_cache 1;
    }   

    # Don’t use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
        set $skip_cache 1;
    }
    ## End Cache

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

#    I was playing around with this         
#    rewrite ^/(wp-.*.php)$ /wp$1 last;  
#    rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;

    # Rewrite multisite '.../wp-.*' and '.../*.php'.
    if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) /wp$1 last;
        rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ /wp$1 last;
    } 

    location ~ \.php$ {

        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        # Caching (FastCGI) configuration
        fastcgi_cache_bypass $skip_cache;
        fastcgi_no_cache $skip_cache;
        fastcgi_cache WORDPRESS;
        fastcgi_cache_valid 60m;
    }

    # Caching (FastCGI) configuration
    location ~ /purge(/.*) {
        fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
    }

}

@ilibilibom
Copy link

There seems to be config example here
https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

@Daisuke-sama
Copy link

Hi,

I'd like to recommend you following the problem solving method through nginx config. So, you will have the access to all admin panels and network admin panel, as well.

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;

@tmort tmort closed this as completed Oct 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants