Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active January 9, 2023 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haproxytechblog/3014386b2e7468c6b77dcc09c41c64e2 to your computer and use it in GitHub Desktop.
Save haproxytechblog/3014386b2e7468c6b77dcc09c41c64e2 to your computer and use it in GitHub Desktop.
Announcing HAProxy Data Plane API 2.7
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "mirror",
"command": "spoa-mirror --runtime 0 --mirror-url http://test.local",
"user": "myusername",
"group": "mygroupname",
"start-on-reload": "enabled"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/programs?version=1"
program mirror
command spoa-mirror --runtime 0 --mirror-url http://test.local
user myusername
group mygroupname
option start-on-reload
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "php_fpm",
"docroot": "/var/www/myapp",
"index": "index.php",
"path-info": "^(/.+\\.php)(/.*)?$",
"log-stderr": [
{
"global": true
}
]
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/fcgi_apps?version=2"
fcgi-app php_fpm
docroot /var/www/myapp
index index.php
path-info ^(/.+\.php)(/.*)?$
log-stderr global
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "mymailers",
"timeout": 20000
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/mailers_sections?version=4"
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "smtp1",
"address": "192.168.0.1",
"port": 587
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/mailer_entries?version=5"
mailers mymailers
timeout mail 20000
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "website-1",
"error_files": [
{
"code": 400,
"name": "/etc/haproxy/errorfiles/site1/400.http"
},
{
"code": 404,
"name": "/etc/haproxy/errorfiles/site1/404.http"
}
]
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/http_errors_sections?version=3"
http-errors website-1
errorfile 400 /etc/haproxy/errorfiles/site1/400.http
errorfile 404 /etc/haproxy/errorfiles/site1/404.http
mailer smtp1 192.168.0.1:587
$ curl -X POST \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 0,
"status": 503,
"errorfiles": "website-1"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/http_error_rules?parent_type=backend&parent_name=test&version=6"
http-error status 503 errorfiles website-1
defaults http
mode http
timeout connect 10000
timeout client 30000
timeout server 30000
defaults tcp
mode tcp
frontend fe_1 from http
bind 0.0.0.0:80
frontend fe_2 from tcp
bind 0.0.0.0:3000
timeout connect 20000
defaults
mode http
timeout connect 10000
timeout client 30000
timeout server 30000
frontend fe_1
bind 0.0.0.0:80
defaults
mode tcp
frontend fe_2
bind 0.0.0.0:3000
timeout connect 20000
defaults unnamed_defaults_1
mode http
timeout connect 10000
timeout client 30000
timeout server 30000
defaults unnamed_defaults_2
mode tcp
frontend fe_1 from unnamed_defaults_1
bind 0.0.0.0:80
frontend fe_2 from unnamed_defaults_2
bind 0.0.0.0:3000
timeout connect 20000
haproxy:
config_file: "/etc/haproxy/haproxy.cfg"
haproxy_bin: "haproxy"
reload:
reload_cmd: "systemctl reload haproxy"
restart_cmd: "systemctl restart haproxy"
status_cmd: "systemctl status haproxy"
reload_cmd: "sudo -n systemctl reload haproxy.service"
restart_cmd: "sudo -n systemctl restart haproxy.service"
status_cmd: "systemctl --quiet is-active haproxy.service"
reload_cmd: "s6-svc -2 /etc/service.d/haproxy"
restart_cmd: "s6-svc -r /etc/service.d/haproxy"
status_cmd: "s6-svstat -u /etc/service.d/haproxy"
haproxy:
config_file: "/etc/haproxy/haproxy.cfg"
haproxy_bin: "haproxy"
reload:
reload_strategy: "systemd"
service_name: "haproxy-2.4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment