Skip to content

Commit f5584c8

Browse files
committed
Update script and config file
1 parent 13c7e30 commit f5584c8

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

.env.sample

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# .env file to set upa your webproxy enviornment
1+
#
2+
# WEBPROXY
3+
#
4+
# A Web Proxy using docker with NGINX with Let's Encrypt
5+
# And our great community docker-gen, nginx-proxy and docker-letsencrypt-nginx-proxy-companion
6+
#
7+
# This is the .env file to set up your webproxy enviornment
28

39
# Define the names for your local containers
4-
# You do not need to modify this option
5-
NGINX_WEB=nginx
10+
NGINX_WEB=nginx-web
611
DOCKER_GEN=nginx-gen
712
LETS_ENCRYPT=nginx-letsencrypt
813

nginx.tmpl

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ map $http_upgrade $proxy_connection {
4242
server_names_hash_bucket_size 128;
4343

4444
# Default dhparam
45-
ssl_dhparam /etc/nginx/certs/dhparam.pem;
45+
{{ if (exists "/etc/nginx/dhparam/dhparam.pem") }}
46+
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
47+
{{ end }}
4648

4749
# Set appropriate X-Forwarded-Ssl header
4850
map $scheme $proxy_x_forwarded_ssl {
@@ -58,6 +60,10 @@ log_format vhost '$host $remote_addr - $remote_user [$time_local] '
5860

5961
access_log off;
6062

63+
{{ if $.Env.RESOLVERS }}
64+
resolver {{ $.Env.RESOLVERS }};
65+
{{ end }}
66+
6167
{{ if (exists "/etc/nginx/proxy.conf") }}
6268
include /etc/nginx/proxy.conf;
6369
{{ else }}
@@ -118,7 +124,7 @@ upstream {{ $upstream_name }} {
118124

119125
{{ range $knownNetwork := $CurrentContainer.Networks }}
120126
{{ 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"))) }}
122128
## Can be connect with "{{ $containerNetwork.Name }}" network
123129

124130
{{/* If only 1 port exposed, use that */}}
@@ -143,9 +149,19 @@ upstream {{ $upstream_name }} {
143149
{{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}}
144150
{{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
145151

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+
146158
{{/* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}}
147159
{{ $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) "redirect" }}
148160

161+
{{/* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}}
162+
{{ $vhost_root := or (first (groupByKeys $containers "Env.VIRTUAL_ROOT")) "/var/www/public" }}
163+
164+
149165
{{/* Get the first cert name defined by containers w/ the same vhost */}}
150166
{{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }}
151167

@@ -183,6 +199,11 @@ server {
183199
{{ end }}
184200
access_log /var/log/nginx/access.log vhost;
185201

202+
{{ if eq $network_tag "internal" }}
203+
# Only allow traffic from internal clients
204+
include /etc/nginx/network_internal.conf;
205+
{{ end }}
206+
186207
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
187208
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';
188209

@@ -198,6 +219,12 @@ server {
198219
ssl_dhparam {{ printf "/etc/nginx/certs/%s.dhparam.pem" $cert }};
199220
{{ end }}
200221

222+
{{ if (exists (printf "/etc/nginx/certs/%s.chain.crt" $cert)) }}
223+
ssl_stapling on;
224+
ssl_stapling_verify on;
225+
ssl_trusted_certificate {{ printf "/etc/nginx/certs/%s.chain.crt" $cert }};
226+
{{ end }}
227+
201228
{{ if (ne $https_method "noredirect") }}
202229
add_header Strict-Transport-Security "max-age=31536000";
203230
{{ end }}
@@ -212,6 +239,10 @@ server {
212239
{{ if eq $proto "uwsgi" }}
213240
include uwsgi_params;
214241
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
242+
{{ else if eq $proto "fastcgi" }}
243+
root {{ trim $vhost_root }};
244+
include fastcgi.conf;
245+
fastcgi_pass {{ trim $upstream_name }};
215246
{{ else }}
216247
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
217248
{{ end }}
@@ -220,11 +251,11 @@ server {
220251
auth_basic "Restricted {{ $host }}";
221252
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
222253
{{ 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 }}
254+
{{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
255+
include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
256+
{{ else if (exists "/etc/nginx/vhost.d/default_location") }}
257+
include /etc/nginx/vhost.d/default_location;
258+
{{ end }}
228259
}
229260
}
230261

@@ -240,6 +271,11 @@ server {
240271
{{ end }}
241272
access_log /var/log/nginx/access.log vhost;
242273

274+
{{ if eq $network_tag "internal" }}
275+
# Only allow traffic from internal clients
276+
include /etc/nginx/network_internal.conf;
277+
{{ end }}
278+
243279
{{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
244280
include {{ printf "/etc/nginx/vhost.d/%s" $host }};
245281
{{ else if (exists "/etc/nginx/vhost.d/default") }}
@@ -250,18 +286,22 @@ server {
250286
{{ if eq $proto "uwsgi" }}
251287
include uwsgi_params;
252288
uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
289+
{{ else if eq $proto "fastcgi" }}
290+
root {{ trim $vhost_root }};
291+
include fastcgi.conf;
292+
fastcgi_pass {{ trim $upstream_name }};
253293
{{ else }}
254294
proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
255295
{{ end }}
256296
{{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
257297
auth_basic "Restricted {{ $host }}";
258298
auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
259299
{{ 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 }}
300+
{{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
301+
include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
302+
{{ else if (exists "/etc/nginx/vhost.d/default_location") }}
303+
include /etc/nginx/vhost.d/default_location;
304+
{{ end }}
265305
}
266306
}
267307

run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ fi
1313
# 2. Create docker network
1414
docker network create $NETWORK
1515

16-
# 3. Start proxy
16+
# 3. Download the latest version of nginx.tmpl
17+
curl https://raw.githubusercontent.com/jwilder/nginx-proxy/master/nginx.tmpl > nginx.tmpl
18+
19+
# 4. Start proxy
1720
docker-compose up -d
1821

1922

0 commit comments

Comments
 (0)