|
|
|
@ -1,3 +1,10 @@ |
|
|
|
|
################################### |
|
|
|
|
# Generated by confd {{datetime}} # |
|
|
|
|
# ####### # |
|
|
|
|
# # k3d # # |
|
|
|
|
# ####### # |
|
|
|
|
################################### |
|
|
|
|
|
|
|
|
|
{{- $servers := split (getenv "SERVERS") "," -}} |
|
|
|
|
{{- $ports := split (getenv "PORTS") "," -}} |
|
|
|
|
{{- $udp_ports := split (getenv "UDP_PORTS") "," -}} |
|
|
|
@ -12,42 +19,28 @@ events { |
|
|
|
|
|
|
|
|
|
stream { |
|
|
|
|
|
|
|
|
|
####### |
|
|
|
|
# TCP # |
|
|
|
|
####### |
|
|
|
|
{{- range $port := $ports }} |
|
|
|
|
upstream server_nodes_{{ $port }} { |
|
|
|
|
{{- range $server := $servers }} |
|
|
|
|
server {{ $server }}:{{ $port }} max_fails=1 fail_timeout=10s; |
|
|
|
|
{{- end }} |
|
|
|
|
} |
|
|
|
|
{{- range $portstring := lsdir "/ports" }} |
|
|
|
|
|
|
|
|
|
server { |
|
|
|
|
listen {{ $port }}; |
|
|
|
|
proxy_pass server_nodes_{{ $port }}; |
|
|
|
|
proxy_timeout 600; |
|
|
|
|
proxy_connect_timeout 2s; |
|
|
|
|
} |
|
|
|
|
{{- end }} |
|
|
|
|
|
|
|
|
|
####### |
|
|
|
|
# UDP # |
|
|
|
|
####### |
|
|
|
|
{{- $portdir := printf "/ports/%s/*" $portstring -}} |
|
|
|
|
{{- $port := index (split $portstring ".") 0 -}} |
|
|
|
|
{{- $protocol := index (split $portstring ".") 1 -}} |
|
|
|
|
{{- $upstream := replace $portstring "." "_" -1 }} |
|
|
|
|
|
|
|
|
|
{{- range $port := $udp_ports }} |
|
|
|
|
{{- if $port }} |
|
|
|
|
upstream server_nodes_udp_{{ $port }} { |
|
|
|
|
{{- range $server := $servers }} |
|
|
|
|
upstream {{ $upstream }} { |
|
|
|
|
{{- range $server := getvs $portdir }} |
|
|
|
|
server {{ $server }}:{{ $port }} max_fails=1 fail_timeout=10s; |
|
|
|
|
{{- end }} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
server { |
|
|
|
|
listen {{ $port }} udp; |
|
|
|
|
proxy_pass server_nodes_udp_{{ $port }}; |
|
|
|
|
listen {{ $port }} {{- if (eq $protocol "udp") }} udp{{- end -}}; |
|
|
|
|
proxy_pass {{ $upstream }}; |
|
|
|
|
proxy_timeout 600; |
|
|
|
|
proxy_connect_timeout 2s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{{- end }} |
|
|
|
|
{{- end }} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|