Skip to content

Commit 12961e6

Browse files
committed
Add Host header support to http health check.
1 parent c38dc9b commit 12961e6

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33

4+
## 2020-03-26 (1.8-1.5)
5+
6+
- Add HTTPCHK_HOST variable to allow health check to include "Host: xyz.com" HTTP Header. Defaults to "localhost"
7+
48
## 2019-11-28 (1.8-1.5)
59

610
- Add COOKIES_PARAMS variable to give the possibility to add expiration time to cookies

haproxy/Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ either when running the container or in a `docker-compose.yml` file.
147147
* `TIMEOUT_CLIENT` timeouts apply when the client is expected to acknowledge or send data during the TCP process. Default `50000` ms
148148
* `TIMEOUT_SERVER` timeouts apply when the server is expected to acknowledge or send data during the TCP process. Default `50000` ms
149149
* `HTTPCHK` The HTTP method and uri used to check on the servers health - default `HEAD /`
150+
* `HTTPCHK_HOST` Host Header override on http Health Check - default `localhost`
150151
* `INTER` parameter sets the interval between two consecutive health checks. If not specified, the default value is `2s`
151152
* `FAST_INTER` parameter sets the interval between two consecutive health checks when the server is any of the transition state (read above): UP - transitionally DOWN or DOWN - transitionally UP. If not set, then `INTER` is used.
152153
* `DOWN_INTER` parameter sets the interval between two consecutive health checks when the server is in the DOWN state. If not set, then `INTER` is used.

haproxy/docker-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if ! test -e /etc/haproxy/haproxy.cfg; then
4545
if [ ! -z "$FRONTEND_PORT" ]; then echo "export FRONTEND_PORT=\"$FRONTEND_PORT\"" >> /etc/environment; fi
4646
if [ ! -z "$FRONTEND_MODE" ]; then echo "export FRONTEND_MODE=\"$FRONTEND_MODE\"" >> /etc/environment; fi
4747
if [ ! -z "$HTTPCHK" ]; then echo "export HTTPCHK=\"$HTTPCHK\"" >> /etc/environment; fi
48+
if [ ! -z "$HTTPCHK_HOST" ]; then echo "export HTTPCHK_HOST=\"$HTTPCHK_HOST\"" >> /etc/environment; fi
4849
if [ ! -z "$INTER" ]; then echo "export INTER=\"$INTER\"" >> /etc/environment; fi
4950
if [ ! -z "$LOGGING" ]; then echo "export LOGGING=\"$LOGGING\"" >> /etc/environment; fi
5051
if [ ! -z "$LOG_LEVEL" ]; then echo "export LOG_LEVEL=\"$LOG_LEVEL\"" >> /etc/environment; fi

haproxy/src/configure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
TIMEOUT_CLIENT = os.environ.get('TIMEOUT_CLIENT', '50000')
2929
TIMEOUT_SERVER = os.environ.get('TIMEOUT_SERVER', '50000')
3030
HTTPCHK = os.environ.get('HTTPCHK', 'HEAD /')
31+
HTTPCHK_HOST = os.environ.get('HTTPCHK_HOST', 'localhost')
3132
INTER = os.environ.get('INTER', '2s')
3233
FAST_INTER = os.environ.get('FAST_INTER', INTER)
3334
DOWN_INTER = os.environ.get('DOWN_INTER', INTER)
@@ -81,7 +82,7 @@
8182
option forwardfor
8283
http-request set-header X-Forwarded-Port %[dst_port]
8384
http-request add-header X-Forwarded-Proto https if { ssl_fc }
84-
option httpchk $httpchk HTTP/1.1\\r\\nHost:localhost
85+
option httpchk $httpchk HTTP/1.1\\r\\nHost:$httpchk_host
8586
""")
8687

8788
backend_conf_plus = Template("""
@@ -107,7 +108,8 @@
107108

108109
if BACKENDS_MODE == 'http':
109110
backend_conf += backend_type_http.substitute(
110-
httpchk=HTTPCHK
111+
httpchk=HTTPCHK,
112+
httpchk_host=HTTPCHK_HOST
111113
)
112114

113115
################################################################################

0 commit comments

Comments
 (0)