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 APIv3 examples in this section use a GET request to /v3/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://localhost:5555/v3/services/haproxy/configuration/frontends"
nix
curl -X GET \--user admin:adminpwd \"http://localhost:5555/v3/services/haproxy/configuration/frontends"
outputjson
[{"default_backend": "webservers","maxconn":2000,"mode":"http","name": "www"}]
outputjson
[{"default_backend": "webservers","maxconn":2000,"mode":"http","name": "www"}]
nix
curl -X GET \--user admin:adminpwd \"http://localhost:5555/v2/services/haproxy/configuration/frontends"
nix
curl -X GET \--user admin:adminpwd \"http://localhost:5555/v2/services/haproxy/configuration/frontends"
outputjson
{"_version": 99,"data": [{"default_backend": "webservers","maxconn":2000,"mode":"http","name": "www"}]}
outputjson
{"_version": 99,"data": [{"default_backend": "webservers","maxconn":2000,"mode":"http","name": "www"}]}
List a specific frontend Jump to heading
To get information about a specific frontend, make a GET request with the name of the frontend. Below, we view information for the frontend named www
:
nix
curl -X GET \--user admin:adminpwd \"http://localhost:5555/v3/services/haproxy/configuration/frontends/www"
nix
curl -X GET \--user admin:adminpwd \"http://localhost:5555/v3/services/haproxy/configuration/frontends/www"
outputjson
{"default_backend": "webservers","maxconn":2000,"mode":"http","name": "www"}
outputjson
{"default_backend": "webservers","maxconn":2000,"mode":"http","name": "www"}
nix
curl -X GET \--user admin:adminpwd \"http://localhost:5555/v2/services/haproxy/configuration/frontends/www"
nix
curl -X GET \--user admin:adminpwd \"http://localhost:5555/v2/services/haproxy/configuration/frontends/www"
outputjson
{"_version": 99,"data":{"default_backend":"webservers","maxconn":2000,"mode":"http","name":"www"}}
outputjson
{"_version": 99,"data":{"default_backend":"webservers","maxconn":2000,"mode":"http","name":"www"}}
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/v3/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://localhost:5555/v3/services/haproxy/configuration/frontends?version=$CFGVER"
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v3/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://localhost:5555/v3/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://localhost: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://localhost: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. Here, we replace the frontend named www
:
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v3/services/haproxy/configuration/version)curl -X PUT \--user admin:adminpwd \-H "Content-Type: application/json" \-d '{"name": "www","mode": "tcp","default_backend":"webservers","maxconn": 1000}' \"http://localhost:5555/v3/services/haproxy/configuration/frontends/www?version=$CFGVER"
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v3/services/haproxy/configuration/version)curl -X PUT \--user admin:adminpwd \-H "Content-Type: application/json" \-d '{"name": "www","mode": "tcp","default_backend":"webservers","maxconn": 1000}' \"http://localhost:5555/v3/services/haproxy/configuration/frontends/www?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": "www","mode": "tcp","default_backend":"webservers","maxconn": 1000}' \"http://localhost:5555/v2/services/haproxy/configuration/frontends/www?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": "www","mode": "tcp","default_backend":"webservers","maxconn": 1000}' \"http://localhost:5555/v2/services/haproxy/configuration/frontends/www?version=$CFGVER"
Delete a frontend Jump to heading
To delete a frontend, use the DELETE method, passing the name of the frontend as part of the URL path. Below we delete the frontend named www
:
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v3/services/haproxy/configuration/version)curl -X DELETE \--user admin:adminpwd \"http://localhost:5555/v3/services/haproxy/configuration/frontends/www?version=$CFGVER"
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v3/services/haproxy/configuration/version)curl -X DELETE \--user admin:adminpwd \"http://localhost:5555/v3/services/haproxy/configuration/frontends/www?version=$CFGVER"
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v2/services/haproxy/configuration/version)curl -X DELETE \--user admin:adminpwd \"http://localhost:5555/v2/services/haproxy/configuration/frontends/www?version=$CFGVER"
nix
CFGVER=$(curl -s -u admin:adminpwd http://localhost:5555/v2/services/haproxy/configuration/version)curl -X DELETE \--user admin:adminpwd \"http://localhost:5555/v2/services/haproxy/configuration/frontends/www?version=$CFGVER"
Do you have any suggestions on how we can improve the content of this page?