How to manage nginx template

I hava some config in nginx,but I don’t know how to manage these

first i use like

        template {
            data        = "{{ key \"slb/nginx/test.conf\" }}"
            destination = "local/conf.d/test.conf"
        }

but can’t discern

``
{{ range service “my-service” }}
server {{ .Address }}:{{ .Port }};
{{ else }}server 127.0.0.1:65535; # force a 502
{{ end }}


then i use like 

    template {
        data        = <<EOF
upstream backend
{
{{ range service "test" }}  server {{ .Address }}:{{ .Port }};
{{ else }}server 127.0.0.1:65535; # force a 502
{{ end }}
}
EOF
but this will cause the nomad file to be very long