-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhaproxy.tmpl
More file actions
130 lines (118 loc) · 6.18 KB
/
Copy pathhaproxy.tmpl
File metadata and controls
130 lines (118 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{{ define "upstream" }}
{{ if .Address }}
{{/* If port is not published on host, use container's IP:PORT */}}
{{ if .Address.IP }}
# {{ .Container.Name }}
server {{ .Address.IP }}:{{ .Address.Port }} {{ .Address.IP }}:{{ .Address.Port }} check
{{ else }}
# {{ .Container.Name }}
server {{ .Container.Name }}:{{ .Address.Port }} {{ .Container.Name }}:{{ .Address.Port }} check init-addr last,libc,none
{{ end }}
{{ end }}
{{ end }}
{{ define "upstream_ssl" }}
{{ if .Address }}
{{/* If port is not published on host, use container's IP:PORT */}}
{{ if .Address.IP }}
# {{ .Container.Name }}
server {{ .Address.IP }}:{{ .Address.Port }} {{ .Address.IP }}:{{ .Address.Port }} check ssl verify none
{{ else }}
# {{ .Container.Name }}
server {{ .Container.Name }}:{{ .Address.Port }} {{ .Container.Name }}:{{ .Address.Port }} check ssl verify none init-addr last,libc,none
{{ end }}
{{ end }}
{{ end }}
global
daemon
maxconn 1024
pidfile /var/run/haproxy.pid
tune.bufsize 32768
defaults
balance roundrobin
timeout client 600s
timeout connect 600s
timeout server 600s
option http-server-close
frontend http
mode http
bind :80
option forwardfor
stats enable
stats refresh 30s
stats show-node
stats uri /stats
{{/* We are only interested in containers that have the environment variable AMAZEEIO set */}}
{{range $key, $container := whereExist $ "Env.AMAZEEIO" }}
{{/* Allow containers to set their hostname via the env variable AMAZEEIO_URL if not set, fall bback to the container name */}}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{end}}
{{/* We are only interested in containers that have the environment variable LAGOON_LOCALDEV_HTTP_PORT set */}}
{{range $key, $container := whereExist $ "Env.LAGOON_LOCALDEV_HTTP_PORT" }}
{{/* Allow containers to set their hostname via the env variable LAGOON_ROUTE if not set, fall back to the container name and projectname. Also remove http:// and https:// */}}
{{$host := replace (replace (coalesce $container.Env.LAGOON_LOCALDEV_URL $container.Env.LAGOON_ROUTE (printf "%s.docker.amazee.io" $container.Name)) "http://" "" 1) "https://" "" 1 }}
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{end}}
{{if exists "/app/server.pem"}}
frontend https
mode http
bind *:443 ssl crt /app/server.pem
http-request add-header X-Forwarded-Proto https
option forwardfor
option socket-stats
stats enable
stats refresh 30s
stats show-node
stats uri /stats
{{range $key, $container := whereExist $ "Env.AMAZEEIO" }}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
use_backend https_{{$host}} if { hdr_dom(host) -i {{$host}} } { nbsrv(https_{{$host}}) gt 0 }
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{end}}
{{range $key, $container := whereExist $ "Env.LAGOON_LOCALDEV_HTTP_PORT" }}
{{/* Allow containers to set their hostname via the env variable LAGOON_ROUTE if not set, fall back to the container name and projectname. Also remove http:// and https:// */}}
{{$host := replace (replace (coalesce $container.Env.LAGOON_LOCALDEV_URL $container.Env.LAGOON_ROUTE (printf "%s.docker.amazee.io" $container.Name)) "http://" "" 1) "https://" "" 1 }}
use_backend http_{{$host}} if { hdr_dom(host) -i {{$host}} }
{{end}}
{{range $key, $container := whereExist $ "Env.LAGOON_LOCALDEV_HTTPS_PORT" }}
{{/* Allow containers to set their hostname via the env variable LAGOON_ROUTE if not set, fall back to the container name and projectname. Also remove http:// and https:// */}}
{{$host := replace (replace (coalesce $container.Env.LAGOON_LOCALDEV_URL $container.Env.LAGOON_ROUTE (printf "%s.docker.amazee.io" $container.Name)) "http://" "" 1) "https://" "" 1 }}
use_backend https_{{$host}} if { hdr_dom(host) -i {{$host}} } { nbsrv(https_{{$host}}) gt 0 }
{{end}}
{{end}}
{{range $key, $container := whereExist $ "Env.AMAZEEIO" }}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
{{/* Allow containers to set their the port for HTTP connections via AMAZEEIO_HTTP_PORT env variable, fallback to Port 80 */}}
{{$http_port := coalesce $container.Env.AMAZEEIO_HTTP_PORT "80" }}
backend http_{{$host}}
mode http
{{ $address := where $container.Addresses "Port" $http_port | first }}
{{ template "upstream" (dict "Container" $container "Address" $address) }}
{{end}}
{{range $key, $container := whereExist $ "Env.AMAZEEIO" }}
{{$host := coalesce $container.Env.AMAZEEIO_URL $container.Name }}
{{/* Allow containers to set their port for HTTPS connections via AMAZEEIO_HTTPS_PORT env variable, fallback to Port 443 */}}
{{$https_port := coalesce $container.Env.AMAZEEIO_HTTPS_PORT "443" }}
backend https_{{$host}}
mode http
{{ $address := where $container.Addresses "Port" $https_port | first }}
{{ template "upstream_ssl" (dict "Container" $container "Address" $address) }}
{{end}}
{{range $key, $container := whereExist $ "Env.LAGOON_LOCALDEV_HTTP_PORT" }}
{{$host := replace (replace (coalesce $container.Env.LAGOON_LOCALDEV_URL $container.Env.LAGOON_ROUTE (printf "%s.docker.amazee.io" $container.Name)) "http://" "" 1) "https://" "" 1 }}
{{/* Allow containers to set their the port for HTTP connections via LAGOON_LOCALDEV_HTTP_PORT env variable, fallback to Port 8080 */}}
{{$http_port := coalesce $container.Env.LAGOON_LOCALDEV_HTTP_PORT "8080" }}
backend http_{{$host}}
mode http
{{ $address := where $container.Addresses "Port" $http_port | first }}
{{ template "upstream" (dict "Container" $container "Address" $address) }}
{{end}}
{{range $key, $container := whereExist $ "Env.LAGOON_LOCALDEV_HTTPS_PORT" }}
{{$host := replace (replace (coalesce $container.Env.LAGOON_LOCALDEV_URL $container.Env.LAGOON_ROUTE (printf "%s.docker.amazee.io" $container.Name)) "http://" "" 1) "https://" "" 1 }}
{{/* Allow containers to set their port for HTTPS connections via LAGOON_LOCALDEV_HTTPS_PORT env variable */}}
{{$https_port := $container.Env.LAGOON_LOCALDEV_HTTPS_PORT }}
backend https_{{$host}}
mode http
{{ $address := where $container.Addresses "Port" $https_port | first }}
{{ template "upstream_ssl" (dict "Container" $container "Address" $address) }}
{{end}}