1
1
# nginx-proxy{{ if $.Env.NGINX_PROXY_VERSION }} version : {{ $.Env.NGINX_PROXY_VERSION }}{{ end }}
2
2
3
3
{{- /*
4
- * Global values. Values are stored in this map rather than in individual
4
+ * Global values. Values are stored in this map rather than in individual
5
5
* global variables so that the values can be easily passed to embedded
6
- * templates. (Go templates cannot access variables outside of their own
7
- * scope.)
6
+ * templates (Go templates cannot access variables outside of their own
7
+ * scope) and displayed in the debug endpoint output.
8
8
*/}}
9
9
{{- $globals := dict }}
10
10
{{- $_ := set $globals "containers" $ }}
15
15
{{- $config := dict }}
16
16
{{- $_ := set $config "nginx_proxy_version" $.Env.NGINX_PROXY_VERSION }}
17
17
{{- $_ := set $config "default_cert_ok" (and (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
18
- {{- $_ := set $config "external_http_port" (coalesce $globals.Env.HTTP_PORT "80") }}
19
- {{- $_ := set $config "external_https_port" (coalesce $globals.Env.HTTPS_PORT "443") }}
20
- {{- $_ := set $config "sha1_upstream_name" (parseBool (coalesce $globals.Env.SHA1_UPSTREAM_NAME "false") ) }}
21
- {{- $_ := set $config "default_root_response" (coalesce $globals.Env.DEFAULT_ROOT "404") }}
22
- {{- $_ := set $config "trust_downstream_proxy" (parseBool (coalesce $globals.Env.TRUST_DOWNSTREAM_PROXY "true") ) }}
18
+ {{- $_ := set $config "external_http_port" ($globals.Env.HTTP_PORT | default "80") }}
19
+ {{- $_ := set $config "external_https_port" ($globals.Env.HTTPS_PORT | default "443") }}
20
+ {{- $_ := set $config "sha1_upstream_name" ($globals.Env.SHA1_UPSTREAM_NAME | default "false" | parseBool ) }}
21
+ {{- $_ := set $config "default_root_response" ($globals.Env.DEFAULT_ROOT | default "404") }}
22
+ {{- $_ := set $config "trust_downstream_proxy" ($globals.Env.TRUST_DOWNSTREAM_PROXY | default "true" | parseBool ) }}
23
23
{{- $_ := set $config "enable_access_log" ($globals.Env.DISABLE_ACCESS_LOGS | default "false" | parseBool | not) }}
24
- {{- $_ := set $config "enable_ipv6" (parseBool (coalesce $globals.Env.ENABLE_IPV6 "false") ) }}
25
- {{- $_ := set $config "ssl_policy" (or ( $globals.Env.SSL_POLICY) "Mozilla-Intermediate") }}
24
+ {{- $_ := set $config "enable_ipv6" ($globals.Env.ENABLE_IPV6 | default "false" | parseBool ) }}
25
+ {{- $_ := set $config "ssl_policy" ($globals.Env.SSL_POLICY | default "Mozilla-Intermediate") }}
26
26
{{- $_ := set $config "enable_debug_endpoint" ($globals.Env.DEBUG_ENDPOINT | default "false") }}
27
+ {{- $_ := set $config "hsts" ($globals.Env.HSTS | default "max-age=31536000") }}
28
+ {{- $_ := set $config "acme_http_challenge" ($globals.Env.ACME_HTTP_CHALLENGE_LOCATION | default "true") }}
29
+ {{- $_ := set $config "enable_http2" ($globals.Env.ENABLE_HTTP2 | default "true") }}
30
+ {{- $_ := set $config "enable_http3" ($globals.Env.ENABLE_HTTP3 | default "false") }}
31
+ {{- $_ := set $config "enable_http_on_missing_cert" ($globals.Env.ENABLE_HTTP_ON_MISSING_CERT | default "true") }}
32
+ {{- $_ := set $config "https_method" ($globals.Env.HTTPS_METHOD | default "redirect") }}
33
+ {{- $_ := set $config "default_host" $globals.Env.DEFAULT_HOST }}
34
+ {{- $_ := set $config "resolvers" $globals.Env.RESOLVERS }}
35
+ {{- /* LOG_JSON is a shorthand that sets logging defaults to JSON format */}}
36
+ {{- $_ := set $config "enable_json_logs" ($globals.Env.LOG_JSON | default "false" | parseBool) }}
37
+ {{- $_ := set $config "log_format" $globals.Env.LOG_FORMAT }}
38
+ {{- $_ := set $config "log_format_escape" $globals.Env.LOG_FORMAT_ESCAPE }}
39
+
27
40
{{- $_ := set $globals "config" $config }}
28
41
29
42
{{- $_ := set $globals "vhosts" (dict) }}
@@ -367,11 +380,11 @@ upstream {{ $vpath.upstream }} {
367
380
{{- end }}
368
381
369
382
{{- $debug_vhost := deepCopy .VHost }}
383
+ {{- $_ := set $debug_vhost "hostname" .Hostname }}
370
384
{{- $_ := set $debug_vhost "paths" $debug_paths }}
371
385
372
386
{{- $debug_response := dict
373
387
"global" .GlobalConfig
374
- "hostname" .Hostname
375
388
"request" (dict
376
389
"host" "$host"
377
390
"https" "$https"
@@ -479,19 +492,16 @@ gzip_types text/plain text/css application/javascript application/json applicati
479
492
* LOG_FORMAT_ESCAPE sets the escape part of the log format
480
493
* LOG_FORMAT sets the log format
481
494
*/}}
482
- {{- $logEscape := printf "escape=%s" (or $globals.Env.LOG_FORMAT_ESCAPE "default") }}
483
- {{- $logFormat := or $globals.Env.LOG_FORMAT `$host $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$upstream_addr"` }}
495
+ {{- $logEscape := $globals.config.log_format_escape | default "default" | printf "escape=%s" }}
496
+ {{- $logFormat := $globals.config.log_format | default `$host $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$upstream_addr"` }}
484
497
485
- {{- if parseBool (or $globals.Env.LOG_JSON "false") }}
486
- {{- /* LOG_JSON is a shorthand
487
- * that sets logging defaults to JSON format
488
- */}}
498
+ {{- if $globals.config.enable_json_logs }}
489
499
# JSON Logging enabled (via LOG_JSON env variable)
490
- {{- $logEscape = printf "escape=%s" (or $globals.Env.LOG_FORMAT_ESCAPE "json") }}
491
- {{- $logFormat = or $globals.Env.LOG_FORMAT `{"time_local":"$time_iso8601","client_ip":"$http_x_forwarded_for","remote_addr":"$remote_addr","request":"$request","status":"$status","body_bytes_sent":"$body_bytes_sent","request_time":"$request_time","upstream_response_time":"$upstream_response_time","upstream_addr":"$upstream_addr","http_referrer":"$http_referer","http_user_agent":"$http_user_agent","request_id":"$request_id"}` }}
500
+ {{- $logEscape = $globals.config.log_format_escape | default "json" | printf "escape=%s" }}
501
+ {{- $logFormat = $globals.config.log_format | default `{"time_local":"$time_iso8601","client_ip":"$http_x_forwarded_for","remote_addr":"$remote_addr","request":"$request","status":"$status","body_bytes_sent":"$body_bytes_sent","request_time":"$request_time","upstream_response_time":"$upstream_response_time","upstream_addr":"$upstream_addr","http_referrer":"$http_referer","http_user_agent":"$http_user_agent","request_id":"$request_id"}` }}
492
502
{{- end }}
493
503
494
- log_format vhost {{ $logEscape }} '{{ or $globals.Env.LOG_FORMAT $logFormat }}';
504
+ log_format vhost {{ $logEscape }} '{{ $logFormat }}';
495
505
496
506
access_log off;
497
507
@@ -512,8 +522,8 @@ access_log off;
512
522
{{- template "ssl_policy" (dict "ssl_policy" $httpContextSslPolicy) }}
513
523
error_log /dev/stderr;
514
524
515
- {{- if $globals.Env.RESOLVERS }}
516
- resolver {{ $globals.Env.RESOLVERS }};
525
+ {{- if $globals.config.resolvers }}
526
+ resolver {{ $globals.config.resolvers }};
517
527
{{- end }}
518
528
519
529
{{- if (exists "/etc/nginx/proxy.conf") }}
@@ -552,7 +562,7 @@ proxy_set_header Proxy "";
552
562
553
563
{{- range $hostname, $vhost := $parsedVhosts }}
554
564
{{- $vhost_data := when (hasKey $globals.vhosts $hostname) (get $globals.vhosts $hostname) (dict) }}
555
- {{- $paths := coalesce $vhost_data.paths (dict) }}
565
+ {{- $paths := $vhost_data.paths | default (dict) }}
556
566
557
567
{{- if (empty $vhost) }}
558
568
{{ $vhost = dict "/" (dict) }}
@@ -562,7 +572,7 @@ proxy_set_header Proxy "";
562
572
{{- if (empty $vpath) }}
563
573
{{- $vpath = dict "dest" "" "port" "default" }}
564
574
{{- end }}
565
- {{- $dest := coalesce $vpath.dest "" }}
575
+ {{- $dest := $vpath.dest | default "" }}
566
576
{{- $port := when (hasKey $vpath "port") (toString $vpath.port) "default" }}
567
577
{{- $path_data := when (hasKey $paths $path) (get $paths $path) (dict) }}
568
578
{{- $path_ports := when (hasKey $path_data "ports") (get $path_data "ports") (dict) }}
@@ -603,12 +613,12 @@ proxy_set_header Proxy "";
603
613
{{- end }}
604
614
605
615
{{- $vhost_data := when (hasKey $globals.vhosts $hostname) (get $globals.vhosts $hostname) (dict) }}
606
- {{- $paths := coalesce $vhost_data.paths (dict) }}
616
+ {{- $paths := $vhost_data.paths | default (dict) }}
607
617
608
618
{{- $tmp_paths := groupByWithDefault $containers "Env.VIRTUAL_PATH" "/" }}
609
619
610
620
{{- range $path, $containers := $tmp_paths }}
611
- {{- $dest := or (first ( groupByKeys $containers "Env.VIRTUAL_DEST")) "" }}
621
+ {{- $dest := groupByKeys $containers "Env.VIRTUAL_DEST" | first | default "" }}
612
622
{{- $port := "legacy" }}
613
623
{{- $path_data := when (hasKey $paths $path) (get $paths $path) (dict) }}
614
624
{{- $path_ports := when (hasKey $path_data "ports") (get $path_data "ports") (dict) }}
@@ -639,12 +649,12 @@ proxy_set_header Proxy "";
639
649
{{- end }}
640
650
641
651
{{- /* Get the VIRTUAL_PROTO defined by containers w/ the same vhost-vpath, falling back to "http". */}}
642
- {{- $proto := trim (or (first ( groupByKeys $vpath_containers "Env.VIRTUAL_PROTO")) "http") }}
652
+ {{- $proto := groupByKeys $vpath_containers "Env.VIRTUAL_PROTO" | first | default "http" | trim }}
643
653
{{- /* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external". */}}
644
- {{- $network_tag := or (first ( groupByKeys $vpath_containers "Env.NETWORK_ACCESS")) "external" }}
654
+ {{- $network_tag := groupByKeys $vpath_containers "Env.NETWORK_ACCESS" | first | default "external" }}
645
655
646
- {{- $loadbalance := first (keys ( groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.loadbalance")) }}
647
- {{- $keepalive := coalesce (first (keys ( groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.keepalive"))) "disabled" }}
656
+ {{- $loadbalance := groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.loadbalance" | keys | first }}
657
+ {{- $keepalive := groupByLabel $vpath_containers "com.github.nginx-proxy.nginx-proxy.keepalive" | keys | first | default "disabled" }}
648
658
649
659
{{- $upstream := $vhost_data.upstream_name }}
650
660
{{- if (not (eq $path "/")) }}
@@ -662,41 +672,41 @@ proxy_set_header Proxy "";
662
672
{{ $vhost_containers = concat $vhost_containers $vpath_containers }}
663
673
{{- end }}
664
674
665
- {{- $certName := first ( groupByKeys $vhost_containers "Env.CERT_NAME") }}
675
+ {{- $certName := groupByKeys $vhost_containers "Env.CERT_NAME" | first }}
666
676
{{- $vhostCert := closest (dir "/etc/nginx/certs") (printf "%s.crt" $hostname) }}
667
677
{{- $vhostCert = trimSuffix ".crt" $vhostCert }}
668
678
{{- $vhostCert = trimSuffix ".key" $vhostCert }}
669
679
{{- $cert := or $certName $vhostCert }}
670
680
{{- $cert_ok := and (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert)) }}
671
681
672
- {{- $enable_debug_endpoint := coalesce ( groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.debug-endpoint" | keys | first) $globals.config.enable_debug_endpoint | parseBool }}
673
- {{- $default := eq $globals.Env.DEFAULT_HOST $hostname }}
674
- {{- $https_method := or (first ( groupByKeys $vhost_containers "Env.HTTPS_METHOD")) $globals.Env.HTTPS_METHOD "redirect" }}
675
- {{- $enable_http_on_missing_cert := parseBool (or (first ( groupByKeys $vhost_containers "Env.ENABLE_HTTP_ON_MISSING_CERT")) $globals.Env.ENABLE_HTTP_ON_MISSING_CERT "true") }}
682
+ {{- $enable_debug_endpoint := groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.debug-endpoint" | keys | first | default $globals.config.enable_debug_endpoint | parseBool }}
683
+ {{- $default := eq $globals.config.default_host $hostname }}
684
+ {{- $https_method := groupByKeys $vhost_containers "Env.HTTPS_METHOD" | first | default $globals.config.https_method }}
685
+ {{- $enable_http_on_missing_cert := groupByKeys $vhost_containers "Env.ENABLE_HTTP_ON_MISSING_CERT" | first | default $globals.config.enable_http_on_missing_cert | parseBool }}
676
686
{{- /* When the certificate is missing we want to ensure that HTTP is enabled; hence switching from 'nohttp' or 'redirect' to 'noredirect' */}}
677
687
{{- if (and $enable_http_on_missing_cert (not $cert_ok) (or (eq $https_method "nohttp") (eq $https_method "redirect"))) }}
678
688
{{- $https_method = "noredirect" }}
679
689
{{- end }}
680
- {{- $http2_enabled := parseBool (or (first (keys ( groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.http2.enable"))) $globals.Env.ENABLE_HTTP2 "true") }}
681
- {{- $http3_enabled := parseBool (or (first (keys ( groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.http3.enable"))) $globals.Env.ENABLE_HTTP3 "false") }}
682
- {{- $acme_http_challenge := or (first ( groupByKeys $vhost_containers "Env.ACME_HTTP_CHALLENGE_LOCATION")) $globals.Env.ACME_HTTP_CHALLENGE_LOCATION "true" }}
690
+ {{- $http2_enabled := groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.http2.enable" | keys | first | default $globals.config.enable_http2 | parseBool }}
691
+ {{- $http3_enabled := groupByLabel $vhost_containers "com.github.nginx-proxy.nginx-proxy.http3.enable" | keys | first | default $globals.config.enable_http3 | parseBool }}
692
+ {{- $acme_http_challenge := groupByKeys $vhost_containers "Env.ACME_HTTP_CHALLENGE_LOCATION" | first | default $globals.config.acme_http_challenge }}
683
693
{{- $acme_http_challenge_legacy := eq $acme_http_challenge "legacy" }}
684
694
{{- $acme_http_challenge_enabled := false }}
685
695
{{- if (not $acme_http_challenge_legacy) }}
686
696
{{- $acme_http_challenge_enabled = parseBool $acme_http_challenge }}
687
697
{{- end }}
688
698
689
699
{{- /* Get the SERVER_TOKENS defined by containers w/ the same vhost, falling back to "". */}}
690
- {{- $server_tokens := trim (or (first ( groupByKeys $vhost_containers "Env.SERVER_TOKENS")) "") }}
700
+ {{- $server_tokens := groupByKeys $vhost_containers "Env.SERVER_TOKENS" | first | default "" | trim }}
691
701
692
702
{{- /* Get the SSL_POLICY defined by containers w/ the same vhost, falling back to empty string (use default). */}}
693
- {{- $ssl_policy := or (first ( groupByKeys $vhost_containers "Env.SSL_POLICY")) "" }}
703
+ {{- $ssl_policy := groupByKeys $vhost_containers "Env.SSL_POLICY" | first | default "" }}
694
704
695
705
{{- /* Get the HSTS defined by containers w/ the same vhost, falling back to "max-age=31536000". */}}
696
- {{- $hsts := or (first ( groupByKeys $vhost_containers "Env.HSTS")) (or $globals.Env.HSTS "max-age=31536000") }}
706
+ {{- $hsts := groupByKeys $vhost_containers "Env.HSTS" | first | default $globals.config.hsts }}
697
707
698
708
{{- /* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}}
699
- {{- $vhost_root := or (first ( groupByKeys $vhost_containers "Env.VIRTUAL_ROOT")) "/var/www/public" }}
709
+ {{- $vhost_root := groupByKeys $vhost_containers "Env.VIRTUAL_ROOT" | first | default "/var/www/public" }}
700
710
701
711
{{- $vhost_data = merge $vhost_data (dict
702
712
"cert" $cert
0 commit comments