Tutorials
Manage frontends
In your load balancer configuration, a frontend
section defines the client-facing proxy that receives requests.
You can manage frontends programmatically via the API endpoint /services/haproxy/configuration/frontends
.
Note
The version
parameter in DELETE, POST, and PUT requests must match the system’s current version. The examples in this section use a GET request to /v2/services/haproxy/configuration/version
to retrieve the version and populate the CFGVER
environment variable for the URL version
parameter.
List frontends Jump to heading
To get a list of frontends, make a GET request to the frontends
endpoint:
nix
curl -X GET \--user admin:adminpwd \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends"
nix
curl -X GET \--user admin:adminpwd \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends"
outputjson
{"_version":1,"data":[{"default_backend":"webservers","name":"fe_main"}]}
outputjson
{"_version":1,"data":[{"default_backend":"webservers","name":"fe_main"}]}
List a specific frontend Jump to heading
To get information about a specific frontend, add its name to end of the URL path. Below, we view information for the frontend named myfrontend
:
nix
curl -X GET \--user admin:adminpwd \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend"
nix
curl -X GET \--user admin:adminpwd \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend"
outputjson
{"_version":2,"data":{"default_backend":"webservers","maxconn":2000,"mode":"http","name":"myfrontend"}}
outputjson
{"_version":2,"data":{"default_backend":"webservers","maxconn":2000,"mode":"http","name":"myfrontend"}}
Add a frontend Jump to heading
To add a frontend, make a POST request to the frontends
endpoint. Send the fields to set in the body of the request. Below, we create a new frontend named myfrontend
.
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v2/services/haproxy/configuration/version)curl -X POST \--user admin:adminpwd \-H "Content-Type: application/json" \-d '{"name": "myfrontend","mode": "http","default_backend": "webservers","maxconn": 2000}' \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends?version=$CFGVER"
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v2/services/haproxy/configuration/version)curl -X POST \--user admin:adminpwd \-H "Content-Type: application/json" \-d '{"name": "myfrontend","mode": "http","default_backend": "webservers","maxconn": 2000}' \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends?version=$CFGVER"
Replace a frontend Jump to heading
To make changes to a frontend, you must replace it entirely. To replace an existing frontend, make a PUT request to the frontends
endpoint, passing the name of the frontend at the end of the URL path:
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v2/services/haproxy/configuration/version)curl -X PUT \--user admin:adminpwd \-H "Content-Type: application/json" \-d '{"name": "myfrontend","mode": "tcp","default_backend":"webservers","maxconn": 1000}' \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend?version=$CFGVER"
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v2/services/haproxy/configuration/version)curl -X PUT \--user admin:adminpwd \-H "Content-Type: application/json" \-d '{"name": "myfrontend","mode": "tcp","default_backend":"webservers","maxconn": 1000}' \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend?version=$CFGVER"
Delete a frontend Jump to heading
To delete a frontend, use the DELETE method:
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v2/services/haproxy/configuration/version)curl -X DELETE \--user admin:adminpwd \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend?version=$CFGVER"
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v2/services/haproxy/configuration/version)curl -X DELETE \--user admin:adminpwd \"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend?version=$CFGVER"
Do you have any suggestions on how we can improve the content of this page?