@@ -49,6 +49,9 @@ upstream {{ .Host }} {
49
49
{{ end }}
50
50
}
51
51
52
+ {{/* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}}
53
+ {{ $https_method := or (first (groupByKeys .Containers "Env.HTTPS_METHOD")) "redirect" }}
54
+
52
55
{{/* Get the first cert name defined by containers w/ the same vhost */}}
53
56
{{ $certName := (first (groupByKeys .Containers "Env.CERT_NAME")) }}
54
57
@@ -62,14 +65,18 @@ upstream {{ .Host }} {
62
65
{{/* Use the cert specifid on the container or fallback to the best vhost match */}}
63
66
{{ $cert := (coalesce $certName $vhostCert) }}
64
67
65
- {{ if (and (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }}
68
+ {{ $is_https := (and (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }}
69
+
70
+ {{ if $is_https }}
66
71
72
+ {{ if eq $https_method "redirect" }}
67
73
server {
68
74
server_name {{ .Host }};
69
75
listen 80;
70
76
access_log /var/log/nginx/access.log vhost;
71
77
return 301 https://{{ .Host }}$request_uri;
72
78
}
79
+ {{ end }}
73
80
74
81
server {
75
82
server_name {{ .Host }};
@@ -112,7 +119,9 @@ server {
112
119
}
113
120
}
114
121
115
- {{ else }}
122
+ {{ end }}
123
+
124
+ {{ if or (not $is_https) (eq $https_method "noredirect") }}
116
125
117
126
server {
118
127
server_name {{ .Host }};
@@ -138,6 +147,14 @@ server {
138
147
{{ end }}
139
148
}
140
149
}
150
+ {{ else if not (eq $https_method "nohttp") }}
151
+ server {
152
+ server_name {{ .Host }};
153
+ listen 80;
154
+ access_log /var/log/nginx/access.log vhost;
155
+ return 503 "Unknown HTTPS_METHOD {{ $https_method }}";
156
+ add_header Content-Type text/plain;
157
+ }
141
158
{{ end }}
142
159
{{ end }}
143
160
0 commit comments