Merge "Modify frontend"
diff --git a/haproxy/files/haproxy.cfg b/haproxy/files/haproxy.cfg
index 3a2283b..26f1768 100644
--- a/haproxy/files/haproxy.cfg
+++ b/haproxy/files/haproxy.cfg
@@ -200,12 +200,21 @@
 {%- for listen_name, listen in proxy.get('listen', {}).iteritems() %}
 {%- if listen.get('format', 'listen') == 'end' %}
 
-frontend  {{ listen_name }} {{ listen.binds[0].address }}:{{ listen.binds[0].port }}
+frontend  {{ listen_name }}
+  bind {{ listen.binds[0].address }}:{{ listen.binds[0].port }}
+  {% if listen.binds[0].get('ssl', {}).enabled|default(False) %}
+  bind {{ listen.binds[0].address }}:{{ listen.binds[0].ssl_port|default('443') }} {% if listen.binds[0].ssl.pem_file is defined %}ssl crt {{ listen.binds[0].ssl.pem_file }}{% else %}ssl crt /etc/haproxy/ssl/{{ listen_name }}{% endif %}
+  redirect scheme https code 301 if !{ ssl_fc }
+  {% endif %}
   {%- for acl in listen.get('acls', []) %}
   {%- for condition in acl.get('conditions', []) %}
   acl {{ acl.name }} {{ condition.type }} {{ condition.condition }}
   {%- endfor %}
-  use_backend {{ acl.name }}-backend   if {{ acl.name }}
+  {%- if listen_name == 'service_proxy' %}
+  use_backend {{ acl.name }} if {{ acl.name }}
+  {% else %}
+  use_backend {{ acl.name }}-backend if {{ acl.name }}
+  {% endif %}
   {%- endfor %}
   default_backend {{ listen_name }}-backend
 
@@ -216,6 +225,7 @@
   {%- for server in listen.get('servers', []) %}
   server {{ server.get('name', server.host) }} {{ server.host }}:{{ server.port }} {{ server.get('params', '') }}
   {%- endfor %}
+{%- if listen_name != 'service_proxy' %}
 {%- for acl in listen.get('acls', []) %}
 
 backend {{ acl.name }}-backend
@@ -225,4 +235,5 @@
   {%- endfor %}
 {%- endfor %}
 {%- endif %}
+{%- endif %}
 {%- endfor %}