HAProxy community

Dynamically Lists Server Backend


Can I dynamically lists all servers backend using lua scripts ? For Example:

Lua Script:

local function choose_backend()
return “server webserver02 lbwebserver-02.perf.lokal:80 check”
core.register_fetches(“choose_backend”, choose_backend)

HA Configuration:

    lua-load /usr/sbin/lua-choose-backend.lua


    use_backend WEBSERVER01

backend WEBSERVER01

I had tried that thing, but haproxy says invalid ‘%’ thing.
I don’t want to use the ‘use_backend’ like internet says, because If I use that way, I would have to add the backends everytime my servers grow. I want to dynamically list those servers on the lua

Is that possible ?


No, that is not how it works at all.

The configuration is parsed at startup, you cannot generate a configuration at runtime in LUA and then feed haproxy with it. That doesn’t work and never will.

Can you explain more thoroughly what you are trying to achieve?