Download the PHP package malc0mn/haproxy-config-builder without Composer
On this page you can find all versions of the php package malc0mn/haproxy-config-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download malc0mn/haproxy-config-builder
More information about malc0mn/haproxy-config-builder
Files in malc0mn/haproxy-config-builder
Package haproxy-config-builder
Short Description HAProxy config file builder and processor.
License MIT
Homepage https://github.com/malc0mn/haproxy-config-builder
Informations about the package haproxy-config-builder
HAProxy Config Processor
Install using composer
Open a shell, cd
to your poject and type:
or edit composer.json and add:
Usage examples
Create from scratch
Read from file
Output ordering
Keywords ordering within a proxy block
By default, the builder output will be printed in the same order you have added
parameters.
This is not always desired, especially when working with ACLs that you want to
be present in the output before you set the use_backend
calls.
To solve this issue, you can use the setParameterOrder()
method to indicate
the desired printing order. An example:
Ordering of proxy blocks in the config file
The proxy blocks will be rendered according to their given priority with some limitations:
global
will always be rendered first (1st).defaults
will always be rendered second (2nd).resolvers
will always be rendered third (3rd).userlist
will always be rendered fourth (4th).- Attempting to set a print priority on
defaults
will throw an exception.
You can thus only control the print priority of backend
, frontend
and
listen
proxy blocks.
The default priority is set to 1000. You can change the priority by calling
the setPrintPriority() method on the desired proxy block: a smaller integer
means a higher priority!
Now what?
Once you have the config, you can use the various helper methods to programatically alter or update the config. Or you can use those helpers to conditionally add or remove settings...
Have a look at the classes to see what is at your disposal. A peek at the tests will give you a very good idea of what you can do with all available methods.
More complex stuff
If you need more complex rules that need multiple use_backend
calls to the
same backend, then you can use tagged backends.
Consider this HAProxy frontend proxy block:
This example uses path mappings to direct traffic to a different backend. It should be obvious that you cannot write this to achieve the same:
The above example will never redirect you to the API backend when calling
the website.example.com/api
url because the first use_backend
statement
will:
- see that the host is
website.example.com
and the path is not/admin
so it will go on to the next condition - see that the host is
website.example.com
and redirect you to thewebsite
backend.
To recreate the first, correct, example using this library, you can use tagged backends:
Credits
The concepts used are based on the Nginx Configuration processor by romanpitak.