4
4
backend for a route and contains all the endpoints for the service
5
5
*/}}
6
6
{{- define "/var/lib/nginx/conf/nginx.config" -}}
7
+ {{- $workingDir := .WorkingDir }}
7
8
#user www www; ## Default: nobody
8
9
worker_processes 5; ## Default: 1
9
10
error_log /var/lib/nginx/logs/error.log;
@@ -32,10 +33,8 @@ http {
32
33
33
34
34
35
{{- range $cfgIdx, $cfg := .State }}
35
- {{- if (eq $cfg.TLSTermination "") }}
36
36
37
- # Plain http backend
38
- upstream be_http_{{$cfgIdx}} {
37
+ upstream be_{{$cfg.Namespace}}_{{$cfg.Name}} {
39
38
{{- range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
40
39
{{- with $serviceUnit := index $.ServiceUnits $serviceUnitName }}
41
40
{{- range $idx, $endpoint := endpointsForAlias $cfg $serviceUnit }}
@@ -46,15 +45,26 @@ http {
46
45
}
47
46
48
47
server { # simple load balancing
48
+ {{- if (eq $cfg.TLSTermination "") }}
49
49
listen 80;
50
+ {{- else }}
51
+ listen 443;
52
+ {{ end -}}
53
+
50
54
server_name {{$cfg.Host}};
51
- access_log /var/lib/nginx/logs/be_http_{{$cfgIdx}}.log main;
55
+ {{- if and (ne $cfg.Host "") (or (eq $cfg.TLSTermination "edge") (eq $cfg.TLSTermination "reencrypt")) -}}
56
+ {{ $cert := index $cfg.Certificates $cfg.Host -}}
57
+ {{ if ne $cert.Contents "" }}
58
+ ssl_certificate {{$workingDir}}/certs/{{$cfgIdx}}.pem;
59
+ ssl_certificate_key {{$workingDir}}/certs/{{$cfgIdx}}.pem;
60
+ {{ end -}}
61
+ {{ end -}}
62
+ access_log /var/lib/nginx/logs/be_{{$cfgIdx}}.log main;
52
63
53
64
location / {
54
- proxy_pass http://be_http_ {{$cfgIdx }};
65
+ proxy_pass http://be_ {{$cfg.Namespace}}_{{$cfg.Name }};
55
66
}
56
67
}
57
- {{ end -}}{{/* end if plain http */}}
58
68
{{ end -}}{{/* end all routes */}}
59
69
}
60
70
{{ end -}}{{/* end config file */}}
0 commit comments