-
Notifications
You must be signed in to change notification settings - Fork 23
/
nginx.tmpl
64 lines (62 loc) · 2.19 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
default $http_x_forwarded_proto;
'' $scheme;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
default upgrade;
'' close;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log off;
# 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 Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
# Mitigate httpoxy attack (see https://github.com/jwilder/nginx-proxy for details)
proxy_set_header Proxy "";
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
listen 80;
access_log /var/log/nginx/access.log vhost;
location = / {
return 200 'nginx is alive';
add_header Content-Type text/plain;
}
location / {
return 503;
}
}
{{ range $name, $container := . }}
upstream {{ $name }} {
{{ range $_, $value := $container }}
server {{ $value.Address }}:{{ $value.Port }};
{{ end }}
}
server {
server_name {{ (index $container 0).Host }};
{{ range $_, $value := $container -}}
{{ range $key, $value := $value.Env -}}
{{ if (eq (index (split $key "_GEN_") 0) "NGINX") }}
{{ replace $key "NGINX_GEN_" "" 1 }} {{ $value }};
{{- end }}
{{- end }}
{{- end }}
listen 80;
access_log /var/log/nginx/access.log vhost;
location / {
proxy_pass http://{{ $name }};
}
}
{{ end }}