diff --git a/internal/mode/static/nginx/config/convert.go b/internal/mode/static/nginx/config/convert.go index d8435a0e22..ff20bf888d 100644 --- a/internal/mode/static/nginx/config/convert.go +++ b/internal/mode/static/nginx/config/convert.go @@ -18,8 +18,13 @@ func ConvertEndpoints(eps []resolver.Endpoint) []ngxclient.UpstreamServer { port = fmt.Sprintf(":%d", ep.Port) } + format := "%s%s" + if ep.IPv6 { + format = "[%s]%s" + } + server := ngxclient.UpstreamServer{ - Server: fmt.Sprintf("%s%s", ep.Address, port), + Server: fmt.Sprintf(format, ep.Address, port), } servers = append(servers, server) diff --git a/internal/mode/static/nginx/config/convert_test.go b/internal/mode/static/nginx/config/convert_test.go index c755f2c3c9..0a3a059fac 100644 --- a/internal/mode/static/nginx/config/convert_test.go +++ b/internal/mode/static/nginx/config/convert_test.go @@ -19,6 +19,11 @@ func TestConvertEndpoints(t *testing.T) { Address: "5.6.7.8", Port: 0, }, + { + Address: "2001:db8::1", + Port: 443, + IPv6: true, + }, } expUpstreams := []ngxclient.UpstreamServer{ @@ -28,6 +33,9 @@ func TestConvertEndpoints(t *testing.T) { { Server: "5.6.7.8", }, + { + Server: "[2001:db8::1]:443", + }, } g := NewWithT(t)