From f4aa7ec5a3e2e0309278b4d91bc4d480a41a4987 Mon Sep 17 00:00:00 2001 From: torz Date: Thu, 28 Apr 2016 09:06:24 +0000 Subject: [PATCH] optional no force https redirect --- nginx.tmpl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nginx.tmpl b/nginx.tmpl index 255cc35..fdb9706 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -94,6 +94,9 @@ upstream {{ $host }} { {{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}} {{ $proto := or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http" }} +{{/* Option to not force https redirect in case you have multiple vhosts and not all need it */}} +{{ $force_https := or (first (groupByKeys $containers "Env.FORCE_HTTPS")) "true" }} + {{/* Get the first cert name defined by containers w/ the same vhost */}} {{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }} @@ -112,12 +115,14 @@ upstream {{ $host }} { server { server_name {{ $host }}; listen 80 {{ $default_server }}; +{{ if (eq $force_https "true") }} access_log /var/log/nginx/access.log vhost; return 301 https://$host$request_uri; } server { server_name {{ $host }}; +{{ end }} listen 443 ssl http2 {{ $default_server }}; access_log /var/log/nginx/access.log vhost;