WordPress on Nginx - Missing admin/toolbar

Hi I've been trying to figure this out for quite some time now, but whatever I do nothing seem to work.

I have a VPS setup running Nginx + Varnish with WordPress multisite.

Everything works fine except the admin/toolbar when browsing the sites. It simply wont load. It loads in the admin area, but when viewing site it doesn't load.

I have checked the "Show Toolbar when viewing site", and I have deactivated all plugins.

Now I have even gone so far as of creating a brand new WP install running only the default stuff, just to see if that works, but still the bar wont show.

I have checked the source code and the strange thing is that the "#wpadminbar" isn't there! But since this is the default theme every code looks fine - wp_head wp_footer is correctly placed.

My guess now is that this is more a server problem, and maybe a Nginx or Varnish issue?

I hope someone can help me figure this out...

-Howie

Topic varnish nginx multisite Wordpress

Category Web


I was having the same problem so I updated my /etc/varnish/default.vcl to this - hard to say if I'm maybe now allowing too many cookies in (? I'll probably only use this on staging rather than production) but it got me my toolbar back!

# Drop any unnecessary cookies sent to Wordpress.
sub vcl_recv {
   // pages that require cookies
   if ((req.url ~ "^/sqlstuff") || (req.url ~ "wp-(login|admin)")) {
       return (pass);
   }

   // unset any cookies we don't want to keep
   if (req.http.cookie && !(req.http.cookie ~ "(wordpress_|wp-settings-)")) {
       unset req.http.cookie;
   }
}

# Drop any unnecessary cookies Wordpress tries to send back to the client.
sub vcl_fetch {
   // pages that require cookies
   if ((req.url ~ "^/sqlstuff") || (req.url ~ "wp-(login|admin)")) {
       return (hit_for_pass);
   }

   // unset any cookies we don't want to keep
   if (req.http.cookie && !(req.http.cookie ~ "(wordpress_|wp-settings-)")) {
       unset beresp.http.set-cookie;
   }
}

If you're using Varnish and you're not seeing the admin bar it's because you probably have a rule in /etc/varnish/default.vcl that looks like this:

sub vcl_recv {
    if (!(req.url ~ "wp-(login|admin)")) {
        unset req.http.cookie;
    }
}

That's going to keep the admin bar from showing up because you're dropping cookie stuff from all pages except ones that match wp-(login|admin). As a test, try removing this and loading your site. If the admin bar shows up, you will want to adjust your Varnish rules.

There are a few different ways of handling things and it varies. You can check for a specific cookie name, URL strings, etc.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.