1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-02-24 09:48:14 +00:00

chore: Consistent indentation

This commit is contained in:
Richard Hansen 2022-05-17 01:19:32 -04:00
parent f20662eeaa
commit 0da38122bd

View File

@ -83,7 +83,7 @@
{{- else if (exists "/etc/nginx/vhost.d/default_location") }} {{- else if (exists "/etc/nginx/vhost.d/default_location") }}
include /etc/nginx/vhost.d/default_location; include /etc/nginx/vhost.d/default_location;
{{- end }} {{- end }}
} }
{{- end }} {{- end }}
{{- define "upstream" }} {{- define "upstream" }}
@ -234,9 +234,9 @@ server {
server_name _; # This is just an invalid value which will never trigger on a real hostname. server_name _; # This is just an invalid value which will never trigger on a real hostname.
server_tokens off; server_tokens off;
listen {{ $external_http_port }}; listen {{ $external_http_port }};
{{- if $enable_ipv6 }} {{- if $enable_ipv6 }}
listen [::]:{{ $external_http_port }}; listen [::]:{{ $external_http_port }};
{{- end }} {{- end }}
{{ $access_log }} {{ $access_log }}
return 503; return 503;
@ -255,63 +255,62 @@ server {
{{- range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }} {{- range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
{{- $host := trim $host }} {{- $host := trim $host }}
{{- $is_regexp := hasPrefix "~" $host }} {{- $is_regexp := hasPrefix "~" $host }}
{{- $upstream_name := when (or $is_regexp $sha1_upstream_name) (sha1 $host) $host }} {{- $upstream_name := when (or $is_regexp $sha1_upstream_name) (sha1 $host) $host }}
{{- $paths := groupBy $containers "Env.VIRTUAL_PATH" }} {{- $paths := groupBy $containers "Env.VIRTUAL_PATH" }}
{{- $nPaths := len $paths }} {{- $nPaths := len $paths }}
{{- if eq $nPaths 0 }}
{{- if eq $nPaths 0 }}
{{- $paths = dict "/" $containers }} {{- $paths = dict "/" $containers }}
{{- end }} {{- end }}
{{- range $path, $containers := $paths }} {{- range $path, $containers := $paths }}
{{- $upstream := $upstream_name }} {{- $upstream := $upstream_name }}
{{- if gt $nPaths 0 }} {{- if gt $nPaths 0 }}
{{- $sum := sha1 $path }} {{- $sum := sha1 $path }}
{{- $upstream = printf "%s-%s" $upstream $sum }} {{- $upstream = printf "%s-%s" $upstream $sum }}
{{- end }} {{- end }}
# {{ $host }}{{ $path }} # {{ $host }}{{ $path }}
{{ template "upstream" (dict "Upstream" $upstream "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }} {{ template "upstream" (dict "Upstream" $upstream "Containers" $containers "Networks" $CurrentContainer.Networks "Debug" $debug_all) }}
{{- end }} {{- end }}
{{- $default_host := or ($.Env.DEFAULT_HOST) "" }} {{- $default_host := or ($.Env.DEFAULT_HOST) "" }}
{{- $default_server := index (dict $host "" $default_host "default_server") $host }} {{- $default_server := index (dict $host "" $default_host "default_server") $host }}
{{- /* Get the SERVER_TOKENS defined by containers w/ the same vhost, falling back to "" */}} {{- /* Get the SERVER_TOKENS defined by containers w/ the same vhost, falling back to "" */}}
{{- $server_tokens := trim (or (first (groupByKeys $containers "Env.SERVER_TOKENS")) "") }} {{- $server_tokens := trim (or (first (groupByKeys $containers "Env.SERVER_TOKENS")) "") }}
{{- /* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}} {{- /* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}}
{{- $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) (or $.Env.HTTPS_METHOD "redirect") }} {{- $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) (or $.Env.HTTPS_METHOD "redirect") }}
{{- /* Get the SSL_POLICY defined by containers w/ the same vhost, falling back to empty string (use default) */}} {{- /* Get the SSL_POLICY defined by containers w/ the same vhost, falling back to empty string (use default) */}}
{{- $ssl_policy := or (first (groupByKeys $containers "Env.SSL_POLICY")) "" }} {{- $ssl_policy := or (first (groupByKeys $containers "Env.SSL_POLICY")) "" }}
{{- /* Get the HSTS defined by containers w/ the same vhost, falling back to "max-age=31536000" */}} {{- /* Get the HSTS defined by containers w/ the same vhost, falling back to "max-age=31536000" */}}
{{- $hsts := or (first (groupByKeys $containers "Env.HSTS")) (or $.Env.HSTS "max-age=31536000") }} {{- $hsts := or (first (groupByKeys $containers "Env.HSTS")) (or $.Env.HSTS "max-age=31536000") }}
{{- /* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}} {{- /* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}}
{{- $vhost_root := or (first (groupByKeys $containers "Env.VIRTUAL_ROOT")) "/var/www/public" }} {{- $vhost_root := or (first (groupByKeys $containers "Env.VIRTUAL_ROOT")) "/var/www/public" }}
{{- /* Get the first cert name defined by containers w/ the same vhost */}} {{- /* Get the first cert name defined by containers w/ the same vhost */}}
{{- $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }} {{- $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }}
{{- /* Get the best matching cert by name for the vhost. */}} {{- /* Get the best matching cert by name for the vhost. */}}
{{- $vhostCert := (closest (dir "/etc/nginx/certs") (printf "%s.crt" $host))}} {{- $vhostCert := (closest (dir "/etc/nginx/certs") (printf "%s.crt" $host))}}
{{- /* vhostCert is actually a filename so remove any suffixes since they are added later */}} {{- /* vhostCert is actually a filename so remove any suffixes since they are added later */}}
{{- $vhostCert := trimSuffix ".crt" $vhostCert }} {{- $vhostCert := trimSuffix ".crt" $vhostCert }}
{{- $vhostCert := trimSuffix ".key" $vhostCert }} {{- $vhostCert := trimSuffix ".key" $vhostCert }}
{{- /* Use the cert specified on the container or fallback to the best vhost match */}} {{- /* Use the cert specified on the container or fallback to the best vhost match */}}
{{- $cert := (coalesce $certName $vhostCert) }} {{- $cert := (coalesce $certName $vhostCert) }}
{{- $is_https := (and (ne $https_method "nohttps") (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }} {{- $is_https := (and (ne $https_method "nohttps") (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }}
{{- if and $is_https (eq $https_method "redirect") }} {{- if and $is_https (eq $https_method "redirect") }}
server { server {
server_name {{ $host }}; server_name {{ $host }};
{{- if $server_tokens }} {{- if $server_tokens }}
@ -323,7 +322,7 @@ server {
{{- end }} {{- end }}
{{ $access_log }} {{ $access_log }}
# Do not HTTPS redirect Let'sEncrypt ACME challenge # Do not HTTPS redirect Let's Encrypt ACME challenge
location ^~ /.well-known/acme-challenge/ { location ^~ /.well-known/acme-challenge/ {
auth_basic off; auth_basic off;
auth_request off; auth_request off;
@ -341,7 +340,7 @@ server {
{{- end }} {{- end }}
} }
} }
{{- end }} {{- end }}
server { server {
server_name {{ $host }}; server_name {{ $host }};
@ -417,7 +416,7 @@ server {
{{- end }} {{- end }}
} }
{{- if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }} {{- if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
server { server {
server_name {{ $host }}; server_name {{ $host }};
{{- if $server_tokens }} {{- if $server_tokens }}
@ -433,6 +432,6 @@ server {
ssl_certificate /etc/nginx/certs/default.crt; ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key; ssl_certificate_key /etc/nginx/certs/default.key;
} }
{{- end }} {{- end }}
{{- end }} {{- end }}