Question

How to best load balance a WordPress/WooCommerce e-commerce site?

I have been running my WordPress/WooCommerce e-commerce and membership site happily for a couple of years now all on one server. But my traffic and membership is such that I want to transition to a more fault tolerant setup. I was thinking of the following:

  • 1 DB server
  • 2 WordPress servers (setup using easyengine with NGINX, PHP7)
  • 1 Load Balancer

The above setup should be all I need for now, but I have a few questions:

  1. SSL passthrough to each of the WP servers or not? What happens when someone makes a purchase if SSL is terminated on the Load Balancer? Does this all just work seamlessly with authorize.net (or other gateways) or are there some issues there?

  2. Are there specific nginx config or session gotchas in this scenario?

  3. What about server naming? What are the server names in each of the WP servers if they are sharing the same DB? how do I make them different? DO i need to make them different?

  4. Anything else I should be aware of?

Thanks!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Well, in case anyone was interested, here is what I ended up doing:

After reading up on GlusterFS, I had a ton of reservations about performance issues for my needs. In short, it is apparently horrible for the multiple small files scenario that my wordpress sites represent, and much better suited to medium to large media files. So instead, I set up lsyncd from wp1 to wp2, and although it is a few seconds delay to copy/sync, it is more than adequate for my needs.

For setting up the load balancer:

  1. I first pointed my domain to wp1 IP
  2. I then generated a letsencrypt (cert only) so that I would have the cert info I needed.
  3. Then I added this info manually from the files certbot generated to the load balancer
  4. Then I pointed my domain to the load balancer, force all traffic to SSL, and connect to port 80 of my droplets behind the load balancer

For naming my wordpress servers:

  1. I called one of them wp1.mydomain.com and the other wp2.mydomain.com
  2. I manually added entries in the otherwise identical wp-config.php file on each server with the following:
define('WP_HOME','https://wp2.mydomain.com');
define('WP_SITEURL','https://wp2.mydomain.com');
  1. I exclude wp-config.php from my lsyncd setup btw, and sync everything else in /var/www/html

For the DB, both wp1 and wp2 point to the same (third) server (db1.mydomain.com) and serve the identical info.

The only issue may be having to clear the cache manually from time to time on each server individually, but I am looking into creating a button/plugin in the wp admin that will clear both servers’ nginx cache at the same time/on the same click. Other than that, I am super happy with the setup! Anyone have any thoughts or critiques of this approach?

This is a great place to start for a scalable WP installation. https://www.digitalocean.com/community/tutorials/automating-the-deployment-of-a-scalable-wordpress-site

A few caveats I have run into / answers to a couple questions

A note DO does setup PTR records for droplets with names that resolve to their IP address - for example u.x.t1.lb-1.domain.com - add a sub-domain for u.x.t1.lb-1 that points to the domain.com droplet. Something to take into consideration.

Each of your WordPress/Application(s) can access the same DB Server. However in higher traffic situations your DB will become taxed. You could add a Redis Cache Server to your setup to help with this or use use something like the WordPress Plugin HyperDB to spread the database across multiple nodes, or setup a DB cluster - a few choices or combination of choices here. A start - https://docs.jelastic.com/wordpress-cluster

Moving ahead to a more fault tolerant architecture you might want to look at this for your load balancer https://www.digitalocean.com/community/tutorials/how-to-create-a-high-availability-setup-with-heartbeat-and-floating-ips-on-ubuntu-14-04

Another caveat I ran into is keeping each application/wordpress installation in sync with each with assets, plugin/theme versions etc…

The asset(s) aspect could be solved by moving this into DO Spaces - There are many WP Plugins available to help link the space and your media folder up.

As for the application server(s) being in sync, you could move your WP installation into a docker container and store the files on a shared network volume.

Hope this helps

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.