Tutorials

Bind to an address

In your load balancer configuration, a frontend listens for and receives connections from clients. A bind line in a frontend defines the IP address and port on which to listen.

You can manage your binds via the API by calling the endpoint /services/haproxy/configuration/binds.

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 binds Jump to heading

To get a list of existing binds in the fe_main frontend, make a GET request to the binds endpoint. Pass the name of the frontend as an argument:

bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds?frontend=fe_main"
bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds?frontend=fe_main"
output
json
{
"_version":3,
"data":[{
"name":"http",
"port":80
}]
}
output
json
{
"_version":3,
"data":[{
"name":"http",
"port":80
}]
}

List a specific bind Jump to heading

To get information about a specific bind, add its name to the GET call. In the example below, we pass the name https at the end of the endpoint URL:

bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds/https?frontend=fe_main"
bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds/https?frontend=fe_main"
output
json
{
"_version":3,
"data":{
"address":"*",
"alpn":"h2",
"name":"https",
"port":443,
"ssl":true,
"ssl_certificate":"/etc/haproxy/ssl/cert.pem"
}
}
output
json
{
"_version":3,
"data":{
"address":"*",
"alpn":"h2",
"name":"https",
"port":443,
"ssl":true,
"ssl_certificate":"/etc/haproxy/ssl/cert.pem"
}
}

Add a bind Jump to heading

Add a bind to the fe_main frontend by making a POST request to the binds endpoint. Send the fields to set in the body of the request. Note that in this case, because we are sending an update, we also include the version URL parameter:

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X POST \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "https",
"address": "*",
"port": 443,
"alpn": "h2",
"ssl": true,
"ssl_certificate": "/etc/haproxy/ssl/cert.pem"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds?frontend=fe_main&version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X POST \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "https",
"address": "*",
"port": 443,
"alpn": "h2",
"ssl": true,
"ssl_certificate": "/etc/haproxy/ssl/cert.pem"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds?frontend=fe_main&version=$CFGVER"

Replace a bind Jump to heading

To make changes to a bind, you replace it entirely. To replace an existing bind, make a PUT request to the binds endpoint, passing the name of the bind at the end of the URL path. In this case, we are updating the bind named https:

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X PUT \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"address":"*",
"alpn":"h2",
"name":"https",
"port":8443,
"ssl":true,
"ssl_certificate":"/etc/haproxy/ssl/cert.pem"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds/https?frontend=fe_main&version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X PUT \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"address":"*",
"alpn":"h2",
"name":"https",
"port":8443,
"ssl":true,
"ssl_certificate":"/etc/haproxy/ssl/cert.pem"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds/https?frontend=fe_main&version=$CFGVER"

Delete a bind Jump to heading

To delete a bind, use the DELETE method:

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X DELETE \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds/https?frontend=fe_main&version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X DELETE \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/binds/https?frontend=fe_main&version=$CFGVER"

If this page was useful, please, Leave the feedback.