-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsul.tmpl
52 lines (43 loc) · 1.82 KB
/
consul.tmpl
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
global
debug
maxconn 4000
tune.ssl.default-dh-param 2048
defaults
mode http
timeout connect 10000 # default 10 second time out if a backend is not found
timeout client 300000 # 5 min timeout for client
timeout server 300000 # 5 min timeout for server
option forwardfor
option http-server-close
frontend www
bind *:80
bind *:443 ssl crt /certs/
# Generated automatically by consul-template
#tagged services, tag is use for domain information
{{ range $tag, $services := services | byTag }}
{{ range $services}}
acl host_{{ .Name }}_{{ $tag}} hdr(host) -i {{ .Name }}.{{ $tag |replaceAll "_" "." }}
use_backend {{ .Name }}_{{$tag}}_backend if host_{{ .Name }}_{{ $tag }}
{{ end }}
acl default_{{ $tag}} hdr(host) -i {{ $tag |replaceAll "_" "." }}
redirect prefix http://www.{{ $tag |replaceAll "_" "."}} if default_{{ $tag}}
{{ end }}
#not tagged services, the url starting part is used
{{range services}}{{if eq (.Tags |len) 0 }}
acl host_{{ .Name }} hdr(host) -m beg {{ .Name }}.
use_backend {{ .Name }}_backend if host_{{ .Name }}
{{ end }}{{ end }}
#backend definition for tagged services
{{ range $tag, $services := services | byTag }}{{range $services}}
backend {{ .Name }}_{{$tag}}_backend{{ range service (print $tag "." .Name) }}
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
server {{ .Node }} {{ .Address }}:{{ .Port }} check{{ end }}
{{ end }}{{ end }}
#backend definition for untagged services
{{ range services }}{{ if eq (.Tags |len) 0 }}
backend {{ .Name }}_backend{{ range service .Name }}
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
server {{ .Node }} {{ .Address }}:{{ .Port }} check{{ end }}
{{ end }}{{ end }}