lua back-end load balancing

agentzh agentzh at
Fri Jun 10 08:30:42 MSD 2011

On Fri, Jun 10, 2011 at 7:40 AM, Richard Kearsley
<Richard.Kearsley at> wrote:
> I’m using nginx-lua to get some info from a back end “auth” server for each
> request

Sounds cool :)

> The back end server is a simple http server written by myself – i.e. it is
> nowhere near as fast or as optimised as nginx and can therefore be
> considered a bottleneck
> I could run multiple backend server instances to give it a better chance of
> keeping up (i.e. one per cpu core) – but then I’d need to load balance (only
> round-robin style) to the multiple backends in my lua code.

Why not use the nginx upstream block directly? For example:

    upstream backend {

    location = /auth {
         proxy_pass http://backend;

No Lua is required here unless you need to custimize the load
balancing algorithm.

> Is there something I can do in lua code to accomplish this?

If you insist in using Lua, just a quick note on this: the standard
ngx_proxy module supports dynamic resolvers by interpolating nginx
variables into the proxy_pass directive. I think you can use Lua to
compute the value of your nginx variables, which points to a custom
backend server.


More information about the nginx mailing list