WebFaction
Community site: login faq
0
1

I'm looking into options for creating a highly available site on web faction. As far as I've been able to tell, the only option is to set up two identical sites and use DNS round robin.

Are there any other options? For example, is there a way to use something like haproxy to balance between sites on two different servers? Or perhaps by using an Apache module (mod_jk / mod_proxy*)?

I realize that I'm likely limited to web application-only solutions, and that I would have to handle database replication.

My primary goal is to be able to push site updates without downtime (by turning off one site, upgrading it, then repeating the process with the other site).

asked 22 Apr '15, 19:12

_S_
12
accept rate: 0%


I'm personally not familiar with haproxy, but I know it's dead-simple to do load balancing with Nginx.

First create a 'custom app listening on port' application to reserve a port for your Nginx load balancer. For the rest of this example, I'll assume that this app is named "load_balancer" and its been assigned port 54321. Go ahead and assign that app to a website in the panel as well.

After you've created the app in the control panel, SSH into your server and run the following commands to build Nginx:

mkdir ~/src ~/tmp
export TMPDIR=~/tmp
cd ~/src
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz 
cd nginx-1.8.0
./configure --prefix=$HOME/webapps/load_balancer

Next, edit your `~/webapps/load_balancer/conf/nginx.conf to set the port and configure the backend servers that it's going to balance:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    access_log  /home/testweb477/logs/user/load_balancer_access.log;
    error_log  /home/testweb477/logs/user/load_balancer_error.log  warn;

    sendfile        on;
    keepalive_timeout  65;

    upstream backend {
        server server1.domain.com:43210;
        server server2.domain.com:32145;
    }

    server {
        listen       54321;
        server_name  localhost;

        location / {
            proxy_pass http://backend;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Finally, start your Nginx server:

~/webapps/load_balancer/sbin/nginx

At that point, the site to which you assigned the load_balancer application will be proxying requests to server1.domain.com and server2.domain.com, round-robin style. If you want it to handle traffic more-intelligently, you can use the any of the various load-balancing methods described in the Nginx load-balancing guide. For example, if you want to use the least_conn method (so requests fo to the server with the least number of active connections), you would modify the upstream block in the config so that it looks like this:

    upstream backend {
        least_conn;
        server server1.domain.com:43210;
        server server2.domain.com:32145;
    }

Also, note that the backend server configuration above includes the port numbers (random in this example) for the other servers. Be sure to use the "open port" option for those apps on the other servers.

Just remember to restart or reload your Nginx whenever you modify the config.

I'm sure you could do something similar with haproxy, if that's your tool-of-choice. I don't know the exact procedure, butt the core concepts should be the same:

  • Create a 'custom app listening on port' application to reserve a port for haproxy
  • Assign that app to a site
  • Build haproxy from source and configure it listen on the assigned port and proxy traffic to your backend servers.

Hope that helps!

permanent link
This answer is marked "community wiki".

answered 22 Apr '15, 23:40

seanf
12.2k41836
accept rate: 37%

edited 23 Apr '15, 00:13

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×4

question asked: 22 Apr '15, 19:12

question was seen: 1,420 times

last updated: 23 Apr '15, 00:13

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM