WPHighEd

How Nginx & WordPress Are Configured at UMW

VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

WordPress and Nginx

At the University of Mary Washington, we are using a unique implementation of WordPress in more ways than one. On top of the fact that we are running a “multi-network” install of WordPress — allowing us to set up multiple multisite instances in a single installation — we are also running WordPress on a LAMP stack, then running Nginx in front of it as a proxy cache.

Because we are currently using a “desktop” theme and a separate “mobile” theme, we actually have Nginx creating two different versions of the cache for our visitors. When we initially launched, this issue hadn’t occurred to us. Then, after a few hours, we noticed that we were being served the mobile version of the home page when we visited from our desktops; it occurred to us that, immediately after the cache was purged, someone must have visited from a mobile device, WordPress served them the mobile version of the site, and then Nginx created our cache file with that version.

At that point, we modified our Nginx configuration. To begin with, we have Nginx set up to check for the word “mobile” in a visitor’s user-agent. If that’s found, we send them the mobile version of the cache; if not, we send them the normal version. The Nginx config is also set up so that wp-admin and wp-login.php are served directly from Apache, rather than being cached; and if the appropriate WordPress cookie is found (a user is logged in), the entire site is served through Apache.

Apache is now running on ports 81 and 444, while Nginx takes over the standard ports 80 and 443. Our cache is currently configured to clear itself after a cache file has existed for 30 minutes. If we need to manually purge the cache for a page, we can add “/purge” in between the domain name and the path (or “/mobilepurge” to purge the mobile version).

In order to accomplish this in our installation, we’re using two plugins in WordPress. The first is the  “WordPress Nginx proxy cache integrator” plugin, installed and network-activated on all of our networks. Ron Rennick then created a separate plugin for the purge process, which is installed in our mu-plugins folder. He also created our initial Nginx configuration.

The Purge Plugin

See the gist on github.

The Configuration

nginx.conf:

See the gist on github.

default:

See the gist on github.

VN:F [1.9.22_1171]
please wait...
Rating: 0.0/5 (0 votes cast)
Exit mobile version