Skip to content

Commit 6e67bbf

Browse files
authored
Merge pull request #20 from bugre/httpchk_host
Add Host header support to http health check.
2 parents c419690 + 12961e6 commit 6e67bbf

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
@@ -6,6 +6,10 @@
66
- Fixed code to work with new HAProxy configuration location - /usr/local/etc/haproxy/haproxy.cfg
77
- Fix backend port when DNS_ENABLED - refs #24
88

9+
## 2020-03-26 (1.8-1.5)
10+
11+
- Add HTTPCHK_HOST variable to allow health check to include "Host: xyz.com" HTTP Header. Defaults to "localhost"
12+
913
## 2019-11-28 (1.8-1.5)
1014

1115
- 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
@@ -149,6 +149,7 @@ either when running the container or in a `docker-compose.yml` file.
149149
* `TIMEOUT_CLIENT` timeouts apply when the client is expected to acknowledge or send data during the TCP process. Default `50000` ms
150150
* `TIMEOUT_SERVER` timeouts apply when the server is expected to acknowledge or send data during the TCP process. Default `50000` ms
151151
* `HTTPCHK` The HTTP method and uri used to check on the servers health - default `HEAD /`
152+
* `HTTPCHK_HOST` Host Header override on http Health Check - default `localhost`
152153
* `INTER` parameter sets the interval between two consecutive health checks. If not specified, the default value is `2s`
153154
* `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.
154155
* `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
@@ -44,6 +44,7 @@ if ! test -e /usr/local/etc/haproxy/haproxy.cfg; then
4444
if [ ! -z "$FRONTEND_PORT" ]; then echo "export FRONTEND_PORT=\"$FRONTEND_PORT\"" >> /etc/environment; fi
4545
if [ ! -z "$FRONTEND_MODE" ]; then echo "export FRONTEND_MODE=\"$FRONTEND_MODE\"" >> /etc/environment; fi
4646
if [ ! -z "$HTTPCHK" ]; then echo "export HTTPCHK=\"$HTTPCHK\"" >> /etc/environment; fi
47+
if [ ! -z "$HTTPCHK_HOST" ]; then echo "export HTTPCHK_HOST=\"$HTTPCHK_HOST\"" >> /etc/environment; fi
4748
if [ ! -z "$INTER" ]; then echo "export INTER=\"$INTER\"" >> /etc/environment; fi
4849
if [ ! -z "$LOGGING" ]; then echo "export LOGGING=\"$LOGGING\"" >> /etc/environment; fi
4950
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)