Haproxy with Lua Support



Compiling HAProxy with Lua support

Haproxy  requires Lua 5.3 or later. Lua version 5.3  is young and you may not find it with many  Linux distros. But its very easy to build from source as there are not much dependancies

First download source file for lua from here

Build it for linux

Install it

Once installed ,verify the lua  version using

Install Haproxy

Download the source from here

Now you can build it using following command

then install haproxy using

Once installed you can verify the haproxy version using

Here are few example configurations  for  different haproxy-lua implementations

1. Dynamic backends for different Host headers

Consider the situation you have multiple  backend servers for different websites and your loadbalancer has to identify the host header and distribute traffic accordingly

Please check below lua code , which does the vhost-backend mapping

Here is the haproxy config file which uses above lua script

2. Dynamic backend which matches request’s source IP

Another example, consider the situation you have to route the traffic to multiple backends according to source IP of the incoming request

I have posted more sample haproxy-lua scripts here , please checkout.

One thought on “Haproxy with Lua Support

Leave a Reply

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