-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.tmpl
41 lines (36 loc) · 1.09 KB
/
nginx.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
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server {
server_name _;
listen 80;
access_log /var/log/nginx/access.log;
return 503;
}
{{ range $host, $containers := groupByLabel $ "lb.vhost" }}
upstream {{ $host }} {
{{ range $container := $containers }}
{{ $addrLen := len $container.Addresses }}
{{ if eq $addrLen 1 }}
{{ $address := index $container.Addresses 0 }}
server {{ $address.HostIP }}:{{ $address.HostPort }};
{{ else }}
{{ $port := coalesce $container.Labels.lb.servicePort "80" }}
{{ $address := where $container.Addresses "Port" $port | first }}
server {{ $address.HostIP }}:{{ $address.HostPort }};
{{ end }}
{{ end }}
}
server {
server_name {{ $host }};
listen 80;
access_log /var/log/nginx/{{ $host }}-access.log;
location / {
proxy_pass http://{{ trim $host }};
}
}
{{ end }}