Skip to content

Commit 1a03ac3

Browse files
committed
Merge pull request nginx-proxy#49 from md5/reduce-redundancy
Simplify template output
2 parents a912287 + 0306692 commit 1a03ac3

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

nginx.tmpl

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ map $http_upgrade $proxy_connection {
1212
'' '';
1313
}
1414

15+
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
16+
17+
access_log /proc/self/fd/1;
18+
error_log /proc/self/fd/2;
19+
20+
# HTTP 1.1 support
21+
proxy_http_version 1.1;
22+
proxy_buffering off;
23+
proxy_set_header Host $http_host;
24+
proxy_set_header Upgrade $http_upgrade;
25+
proxy_set_header Connection $proxy_connection;
26+
proxy_set_header X-Real-IP $remote_addr;
27+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
28+
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
29+
1530
server {
1631
listen 80 default_server;
1732
server_name _; # This is just an invalid value which will never trigger on a real hostname.
@@ -22,31 +37,27 @@ server {
2237

2338
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
2439
upstream {{ $host }} {
25-
26-
{{ range $index, $value := $containers }}
27-
28-
{{ $addrLen := len $value.Addresses }}
40+
{{ range $container := $containers }}
41+
{{ $addrLen := len $container.Addresses }}
2942
{{/* If only 1 port exposed, use that */}}
3043
{{ if eq $addrLen 1 }}
31-
{{ with $address := index $value.Addresses 0 }}
32-
# {{$value.Name}}
44+
{{ with $address := index $container.Addresses 0 }}
45+
# {{$container.Name}}
3346
server {{ $address.IP }}:{{ $address.Port }};
3447
{{ end }}
35-
3648
{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}}
37-
{{ else if $value.Env.VIRTUAL_PORT }}
38-
{{ range $i, $address := $value.Addresses }}
39-
{{ if eq $address.Port $value.Env.VIRTUAL_PORT }}
40-
# {{$value.Name}}
49+
{{ else if $container.Env.VIRTUAL_PORT }}
50+
{{ range $address := .Addresses }}
51+
{{ if eq $address.Port $container.Env.VIRTUAL_PORT }}
52+
# {{$container.Name}}
4153
server {{ $address.IP }}:{{ $address.Port }};
4254
{{ end }}
4355
{{ end }}
44-
4556
{{/* Else default to standard web port 80 */}}
4657
{{ else }}
47-
{{ range $i, $address := $value.Addresses }}
58+
{{ range $address := $container.Addresses }}
4859
{{ if eq $address.Port "80" }}
49-
# {{$value.Name}}
60+
# {{$container.Name}}
5061
server {{ $address.IP }}:{{ $address.Port }};
5162
{{ end }}
5263
{{ end }}
@@ -55,24 +66,10 @@ upstream {{ $host }} {
5566
}
5667

5768
server {
58-
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
59-
6069
server_name {{ $host }};
61-
proxy_buffering off;
62-
error_log /proc/self/fd/2;
63-
access_log /proc/self/fd/1;
6470

6571
location / {
6672
proxy_pass http://{{ $host }};
67-
proxy_set_header Host $http_host;
68-
proxy_set_header X-Real-IP $remote_addr;
69-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
70-
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
71-
72-
# HTTP 1.1 support
73-
proxy_http_version 1.1;
74-
proxy_set_header Upgrade $http_upgrade;
75-
proxy_set_header Connection $proxy_connection;
7673
}
7774
}
7875
{{ end }}

0 commit comments

Comments
 (0)