LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

Tutorial – The LowEndCluster – Part 3

Tags: Date/Time: May 12, 2015 @ 1:00 pm, by Maarten Kossen

lowendtutorial

Welcome back to the 3rd part of the LowEndCluster tutorial series! Last time we’ve set up an actual web node which we’re going to put behind a “load balancer”, or actually a proxy, in this tutorial. The result will be that it’s both available over IPv4 and IPv6.

Before we dive into this neat function of NGINX however, let me get back to the LowEndCluster as a whole. Initially, I had two goals in mind: redundancy and scalability. While working on the cluster, I found out that doing both at the same time provides a lot of challenges, some even at the budget-part. My goal was to have a redundant cluster for less than $50/year and I’m going to retain my focus on that. Automatic fail-over and scaling is something I’d like to cover in future tutorials, but not in this series. This means that our filesystem doesn’t technically require KVM machines anymore. I’ll do a wrap-up in the end of what I turned out to be using for this tutorial so you have a nice overview.

Anyway, enough babbling. Let’s get to work!

This time the tutorial is probably even easier than it was the last time, or the time before that. Creating a proxy with NGINX is actually very easy and you only need to do it once and then copy the contents over to your backup server.

I’m still assuming a Debian-based distribution, but since this is NGINX configuration this should work on any OS which has NGINX installed.

First, let’s install NGINX:

sudo apt-get install nginx

Once that’s finished, go to the directory with the site configuration files: /etc/nginx/sites-available. In that directory, create a file named ‘YOURDOMAIN.conf’, so for example: example.net.conf.

In that file (/etc/nginx/sites-available/example.net.conf) past the following content:

server {
listen 80;
listen [::]:80;

server_name example.net;

location / {
proxy_pass http://wordpress.example.net/;
}
}

Now, first of all, what we did here is create a ‘server’ object that tells NGINX a server definition is contained inside it.

The first two lines inside that object:

listen 80;
listen [::]:80;

Tell NGINX to listen on port 80 over IPv4 (first line) and on port 80 over IPv6 (second line). Naturally, if you’d wanted to change the ports, this is where you’d do it. I’m assuming you don’t, as that would kind of ruin this whole plan.

server_name example.net;

Put the server name you want NGINX to listen for on this line. You can add multiple like this:

server_name example.net example.com example.org;

Because we’re not pinning this server to specific IP addresses, be sure to include any subdomains you want NGINX to listen for as well.

This address will also be the address of your WordPress installation. I recommended last time that you’d use your eventual WordPress domain temporarily for your web node; this is the time to configure that here.

Now, on to the last block:

location / {
proxy_pass http://wordpress.example.net/;
}

Here we tell NGINX to pass all requests coming to this server to your WordPress web node. I’ve used an example domain here, but I’d recommend you to pick another domain name for your web nodes (give a different one to each) and configure your primary one here. If that is down, you can easily switch to the other domain and continue serving from that.

With the configuration file all finished, let’s enable it so NGINX knows it needs to load this file:

ln -s /etc/nginx/sites-available/example.net.conf /etc/nginx/sites-enabled/example.net.conf

And finally, restart NGINX:

sudo service nginx restart

And you’re done! If you’ve done all right, you should now be able to go to example.net and find it’s serving your WordPress installation from your web nodes, using an external database server!

Now, in order to make this redundant (or easy to fix in case it goes down), copy over the above


That’s it for this week, short and sweet. There’s more cool things you could do with both NGINX and the cluster. For example, you could have NGINX load balance between multiple web nodes very easily. While in this setup that could put some strain on the database server (and eventually the file system), in another setup it could be really useful.

With the current LowEndSpirit pricing, you could even copy this setup to multiple locations and see if you can start serving your visitors from the server closest to them (albeit with a few challenges).

Next time, it’s filesystem time and we’re going to make that last part redundant as well!

Maarten Kossen was the administrator of LowEndBox from 2013 to 2015, and brought many ideas and improvements to the website during his leadership. Today he is member of our community and LowEndTalk.

5 Comments

  1. “…to pick another domain name for your web nodes (give a different one to each) and configure your primary one here…..”

    I don’t quite understand that part. More explanation please..

    ^_^

    May 13, 2015 @ 2:58 pm | Reply
    • server_name lowendtalk.me www.lowendtalk.me;

      // this is your site name, accesible on www and non-www

      location / {
      proxy_pass http://lowendtalk.com/;
      }

      // this is the website url you want to proxy

      May 15, 2015 @ 3:33 am | Reply
  2. D3matt:

    Great tutorial (as always), I’ve been thinking of doing something like this with all the cheap VMs I got from cloudatcost and maybe in combination with some of the sites from here. You should put links to part 1 and 2 at the beginning though.

    I really appreciate all you do here, both providing cheap VPS listings on one place and also the great tutorials you put up.

    May 15, 2015 @ 2:02 am | Reply
  3. Nick D:

    Gah… finally read these, and the bit I want to see is the filesystem ;) Any idea when this will be written up?

    May 25, 2015 @ 1:02 pm | Reply
  4. 2298:

    These three part tutorials you wrote is similar with what i’ve written three years ago, i even referenced LEB in my first paragraph :D

    http://serversreview.net/nginx-load-balancing-failover-and-geo-location-part-1

    http://serversreview.net/nginx-load-balancing-failover-and-geo-location-part-2

    http://serversreview.net/nginx-load-balancing-failover-and-geo-location-part-3

    sadly, i too sold this blog at that year because i needed money.

    June 7, 2015 @ 9:59 pm | Reply

Leave a Reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

Your email address will not be published. Required fields are marked *