@@ -42,7 +42,9 @@ map $http_upgrade $proxy_connection {
42
42
server_names_hash_bucket_size 128;
43
43
44
44
# Default dhparam
45
+ {{ if (exists "/etc/nginx/dhparam/dhparam.pem") }}
45
46
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
47
+ {{ end }}
46
48
47
49
# Set appropriate X-Forwarded-Ssl header
48
50
map $scheme $proxy_x_forwarded_ssl {
@@ -58,6 +60,10 @@ log_format vhost '$host $remote_addr - $remote_user [$time_local] '
58
60
59
61
access_log off;
60
62
63
+ {{ if $.Env.RESOLVERS }}
64
+ resolver {{ $.Env.RESOLVERS }};
65
+ {{ end }}
66
+
61
67
{{ if (exists "/etc/nginx/proxy.conf") }}
62
68
include /etc/nginx/proxy.conf;
63
69
{{ else }}
@@ -118,7 +124,7 @@ upstream {{ $upstream_name }} {
118
124
119
125
{{ range $knownNetwork := $CurrentContainer.Networks }}
120
126
{{ range $containerNetwork := $container.Networks }}
121
- {{ if or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host") }}
127
+ {{ if (and (ne $containerNetwork.Name "ingress") ( or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host")) ) }}
122
128
## Can be connect with "{{ $containerNetwork.Name }}" network
123
129
124
130
{{/* If only 1 port exposed, use that */}}
@@ -143,9 +149,22 @@ upstream {{ $upstream_name }} {
143
149
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}}
144
150
{{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
145
151
152
+ {{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
153
+ {{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }}
154
+
155
+ {{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
156
+ {{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }}
157
+
146
158
{{/* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}}
147
159
{{ $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) "redirect" }}
148
160
161
+ {{/* Get the HSTS defined by containers w/ the same vhost, falling back to "max-age=31536000" */}}
162
+ {{ $hsts := or (first (groupByKeys $containers "Env.HSTS")) "max-age=31536000" }}
163
+
164
+ {{/* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}}
165
+ {{ $vhost_root := or (first (groupByKeys $containers "Env.VIRTUAL_ROOT")) "/var/www/public" }}
166
+
167
+
149
168
{{/* Get the first cert name defined by containers w/ the same vhost */}}
150
169
{{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }}
151
170
@@ -183,6 +202,11 @@ server {
183
202
{{ end }}
184
203
access_log /var/log/nginx/access.log vhost;
185
204
205
+ {{ if eq $network_tag "internal" }}
206
+ # Only allow traffic from internal clients
207
+ include /etc/nginx/network_internal.conf;
208
+ {{ end }}
209
+
186
210
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
187
211
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:!DSS';
188
212
@@ -198,8 +222,14 @@ server {
198
222
ssl_dhparam {{ printf "/etc/nginx/certs/%s.dhparam.pem" $cert }};
199
223
{{ end }}
200
224
201
- {{ if (ne $https_method "noredirect") }}
202
- add_header Strict-Transport-Security "max-age=31536000";
225
+ {{ if (exists (printf "/etc/nginx/certs/%s.chain.crt" $cert)) }}
226
+ ssl_stapling on;
227
+ ssl_stapling_verify on;
228
+ ssl_trusted_certificate {{ printf "/etc/nginx/certs/%s.chain.crt" $cert }};
229
+ {{ end }}
230
+
231
+ {{ if (and (ne $https_method "noredirect") (ne $hsts "off")) }}
232
+ add_header Strict-Transport-Security "{{ trim $hsts }}";
203
233
{{ end }}
204
234
205
235
{{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
@@ -212,6 +242,10 @@ server {
212
242
{{ if eq $proto "uwsgi" }}
213
243
include uwsgi_params;
214
244
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
245
+ {{ else if eq $proto "fastcgi" }}
246
+ root {{ trim $vhost_root }};
247
+ include fastcgi.conf;
248
+ fastcgi_pass {{ trim $upstream_name }};
215
249
{{ else }}
216
250
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
217
251
{{ end }}
@@ -220,11 +254,11 @@ server {
220
254
auth_basic "Restricted {{ $host }}";
221
255
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
222
256
{{ end }}
223
- {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
224
- include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
225
- {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
226
- include /etc/nginx/vhost.d/default_location;
227
- {{ end }}
257
+ {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
258
+ include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
259
+ {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
260
+ include /etc/nginx/vhost.d/default_location;
261
+ {{ end }}
228
262
}
229
263
}
230
264
@@ -240,6 +274,11 @@ server {
240
274
{{ end }}
241
275
access_log /var/log/nginx/access.log vhost;
242
276
277
+ {{ if eq $network_tag "internal" }}
278
+ # Only allow traffic from internal clients
279
+ include /etc/nginx/network_internal.conf;
280
+ {{ end }}
281
+
243
282
{{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
244
283
include {{ printf "/etc/nginx/vhost.d/%s" $host }};
245
284
{{ else if (exists "/etc/nginx/vhost.d/default") }}
@@ -250,18 +289,22 @@ server {
250
289
{{ if eq $proto "uwsgi" }}
251
290
include uwsgi_params;
252
291
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
292
+ {{ else if eq $proto "fastcgi" }}
293
+ root {{ trim $vhost_root }};
294
+ include fastcgi.conf;
295
+ fastcgi_pass {{ trim $upstream_name }};
253
296
{{ else }}
254
297
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
255
298
{{ end }}
256
299
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
257
300
auth_basic "Restricted {{ $host }}";
258
301
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
259
302
{{ end }}
260
- {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
261
- include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
262
- {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
263
- include /etc/nginx/vhost.d/default_location;
264
- {{ end }}
303
+ {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
304
+ include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
305
+ {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
306
+ include /etc/nginx/vhost.d/default_location;
307
+ {{ end }}
265
308
}
266
309
}
267
310
0 commit comments