Skip to content

Commit

Permalink
Combined HTTP and HTTPS server configs for vhosts
Browse files Browse the repository at this point in the history
  • Loading branch information
lmakarov committed Sep 12, 2018
1 parent 265e629 commit 5c5de6c
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions conf/nginx/conf.d/vhosts.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,12 @@
{{ end }}
{{ end }}

{{/* HTTP server template */}}
{{ define "http" }}
## HTTP
server {
listen 80;
{{ range $host := split .Hosts "," }}

server_name {{ $host }};

{{ end }}

location / {
proxy_pass http://{{ .Upstream }};
}
}
{{ end }}

{{/* HTTPS server template */}}
{{ define "https" }}
{{/* HTTP/HTTPS server template */}}
{{ define "server" }}
## HTTPS
server {

listen 80;
listen 443 ssl http2;
{{ range $host := split .Hosts "," }}

Expand Down Expand Up @@ -121,9 +105,6 @@
{{ end }}
}

{{/* Generate HTTP server config */}}
{{ template "http" (dict "Hosts" $hosts "Upstream" $upstream) }}

{{/* Get the cert name from io.docksal.cert-name container label */}}
{{ $certName := or (index $pr_container.Labels "io.docksal.cert-name") "none" }}
{{/* Unset certName if its value us "none" */}}
Expand All @@ -140,8 +121,8 @@
{{/* Use the cert specified on the container or fallback to the best vhost match */}}
{{ $cert := (coalesce $certName $vhostCert) }}

{{/* Generate HTTPS server config */}}
{{ template "https" (dict "Hosts" $hosts "Upstream" $upstream "Cert" $cert) }}
{{/* Generate HTTP/HTTPS server config */}}
{{ template "server" (dict "Hosts" $hosts "Upstream" $upstream "Cert" $cert) }}

{{ end }}
# -------------------------------------------------- #
Expand Down Expand Up @@ -181,9 +162,6 @@
{{ end }}
}

{{/* Generate HTTP server config */}}
{{ template "http" (dict "Hosts" $hosts "Upstream" $upstream) }}

{{/* Get the cert name from io.docksal.cert-name container label */}}
{{ $certName := or (index $container.Labels "io.docksal.cert-name") "none" }}
{{/* Unset certName if its value us "none" */}}
Expand All @@ -200,9 +178,9 @@
{{/* Use the cert specified on the container or fallback to the best vhost match */}}
{{ $cert := (coalesce $certName $vhostCert) }}

{{/* Generate HTTPS server config */}}
{{ template "https" (dict "Hosts" $hosts "Upstream" $upstream "Cert" $cert) }}
{{/* Generate HTTP/HTTPS server config */}}
{{ template "server" (dict "Hosts" $hosts "Upstream" $upstream "Cert" $cert) }}

{{ end }}

{{/* END: Support standalone Docker containers */}}
{{/* END: Support standalone Docker containers */}}

0 comments on commit 5c5de6c

Please sign in to comment.