Skip to content

Commit

Permalink
Add Host header support to http health check.
Browse files Browse the repository at this point in the history
  • Loading branch information
bugre committed Mar 31, 2020
1 parent c38dc9b commit 12961e6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


## 2020-03-26 (1.8-1.5)

- Add HTTPCHK_HOST variable to allow health check to include "Host: xyz.com" HTTP Header. Defaults to "localhost"

## 2019-11-28 (1.8-1.5)

- Add COOKIES_PARAMS variable to give the possibility to add expiration time to cookies
Expand Down
1 change: 1 addition & 0 deletions haproxy/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ either when running the container or in a `docker-compose.yml` file.
* `TIMEOUT_CLIENT` timeouts apply when the client is expected to acknowledge or send data during the TCP process. Default `50000` ms
* `TIMEOUT_SERVER` timeouts apply when the server is expected to acknowledge or send data during the TCP process. Default `50000` ms
* `HTTPCHK` The HTTP method and uri used to check on the servers health - default `HEAD /`
* `HTTPCHK_HOST` Host Header override on http Health Check - default `localhost`
* `INTER` parameter sets the interval between two consecutive health checks. If not specified, the default value is `2s`
* `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.
* `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.
Expand Down
1 change: 1 addition & 0 deletions haproxy/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ if ! test -e /etc/haproxy/haproxy.cfg; then
if [ ! -z "$FRONTEND_PORT" ]; then echo "export FRONTEND_PORT=\"$FRONTEND_PORT\"" >> /etc/environment; fi
if [ ! -z "$FRONTEND_MODE" ]; then echo "export FRONTEND_MODE=\"$FRONTEND_MODE\"" >> /etc/environment; fi
if [ ! -z "$HTTPCHK" ]; then echo "export HTTPCHK=\"$HTTPCHK\"" >> /etc/environment; fi
if [ ! -z "$HTTPCHK_HOST" ]; then echo "export HTTPCHK_HOST=\"$HTTPCHK_HOST\"" >> /etc/environment; fi
if [ ! -z "$INTER" ]; then echo "export INTER=\"$INTER\"" >> /etc/environment; fi
if [ ! -z "$LOGGING" ]; then echo "export LOGGING=\"$LOGGING\"" >> /etc/environment; fi
if [ ! -z "$LOG_LEVEL" ]; then echo "export LOG_LEVEL=\"$LOG_LEVEL\"" >> /etc/environment; fi
Expand Down
6 changes: 4 additions & 2 deletions haproxy/src/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TIMEOUT_CLIENT = os.environ.get('TIMEOUT_CLIENT', '50000')
TIMEOUT_SERVER = os.environ.get('TIMEOUT_SERVER', '50000')
HTTPCHK = os.environ.get('HTTPCHK', 'HEAD /')
HTTPCHK_HOST = os.environ.get('HTTPCHK_HOST', 'localhost')
INTER = os.environ.get('INTER', '2s')
FAST_INTER = os.environ.get('FAST_INTER', INTER)
DOWN_INTER = os.environ.get('DOWN_INTER', INTER)
Expand Down Expand Up @@ -81,7 +82,7 @@
option forwardfor
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
option httpchk $httpchk HTTP/1.1\\r\\nHost:localhost
option httpchk $httpchk HTTP/1.1\\r\\nHost:$httpchk_host
""")

backend_conf_plus = Template("""
Expand All @@ -107,7 +108,8 @@

if BACKENDS_MODE == 'http':
backend_conf += backend_type_http.substitute(
httpchk=HTTPCHK
httpchk=HTTPCHK,
httpchk_host=HTTPCHK_HOST
)

################################################################################
Expand Down

0 comments on commit 12961e6

Please sign in to comment.