When we moved to WordPress, we ran into an issue with our load balanced servers – you can’t add a post to each server individually because of the unique post number added by wordpress when you publish – the post will have a different URL on each server which, because traffic could go to any server, will result in a 404-error lottery – with the chance of the correct page being displayed being 1 in x (x being the number of servers you are balancing the traffic across).
If you’re big enough to use clustering, then you will probably have ways to get around this, however if you aren’t, it could get problematic and clustering would take some expertise and know how to set up.
The way we solved this also helped improve the level of security with our web servers – an issue that any security aware organisation uses open source software will be well aware of.
The answer was to employ an internal staging server – we could test all content amendments and updates on this server before rolling them out to the live servers. Previously we would have to take a server out of the load balancing ‘array’, make changes, test and then copy the changes across to the live servers before releasing the server used for testing back into the array. This was a pain and it reduced the level of resilience as the number of servers used for load balancing was reduced.
So how do you copy the changes from a staging server to your live servers? Simply use a script that dumps the database and then copies the database across to the live servers along with any updated files (do this using using rsync over ssh). The script then runs a remote script sitting on each of the live servers that automatically imports the transferred database and bingo – new content is copied across and live on all your load balanced servers.
How does this improve security? Well now you can disable access to to wp-admin, wp-login.php and any other admin area of the site on the live servers by using .htaccess files or custom php rules. Simply omit these files from being included in the rsync process (see ignoring files during rsync) and you can help ensure that your WordPress server stays yours.
Additionally, and I really like this, if WordPress does get hacked (and it may not be immediately obvious that this has happened), then the security & integrity of your database and code is no longer known. All you need do is upload the files and database from the staging server (which isn’t publicly accessible) and you’re back in the game.
One last thing – using the auto update script also makes it really easy to upgrade WordPress. Do it on the staging server – test your content and plugins and then roll out the upgrade to your load balanced servers simultaneously.
Leave a Reply