Add redirection capabilities to the frontend

This commit is contained in:
John Keates 2015-05-17 15:47:47 +02:00
parent 5afcfd5820
commit 454c5ba973
4 changed files with 23 additions and 2 deletions

View File

@ -55,6 +55,7 @@ Currently, only a handful of options can be set using the pillar:
+ name: the name haproxy will use for the frontend
+ bind: the bind string: this allows you to set the IP, Port and other paramters for the bind
+ redirect: add a redirect line, an unparsed string like in the backend
+ reqadd: an array of reqadd statements. Looped over and put in the configuration, no parsing
+ default_backend: sets the default backend
+ acls: a list of acls, not parsed, simply looped and put in to the configuration

View File

@ -1,3 +1,14 @@
# Because on Ubuntu we don't have a current HAProxy in the usual repo, we add a PPA
{% if salt['grains.get']('osfullname') == 'Ubuntu' %}
haproxy_ppa_repo:
pkgrepo.managed:
- ppa: vbernat/haproxy-1.5
- require_in:
- pkg: haproxy.install
- watch_in:
- pkg: haproxy.install
{% endif %}
haproxy.install:
pkg.installed:
- name: haproxy
- name: haproxy

View File

@ -56,6 +56,10 @@ defaults
{%- for frontend in salt['pillar.get']('haproxy:frontends', {}).iteritems() %}
frontend {{ frontend[1].name }}
bind {{ frontend[1].bind }}
{%- if 'redirects' in backend[1] %}
{%- for redirect in frontend[1].redirects %}
redirect {{ redirect }}{% endfor %}
{-% endif %}
{%- if 'acls' in frontend[1] %}
{%- for acl in frontend[1].acls %}
acl {{ acl }}
@ -82,10 +86,14 @@ frontend {{ frontend[1].name }}
{%- if 'backends' in salt['pillar.get']('haproxy', {}) %}
{%- for backend in salt['pillar.get']('haproxy:backends', {}).iteritems() %}
backend {{ backend[1].name }}
{%- if 'redirects' in backend[1] %}
{%- for redirect in backend[1].redirects %}
redirect {{ redirect }}{% endfor %}
{-% endif %}
balance {{ backend[1].balance }}
{%- if 'servers' in backend[1] %}
{%- for server in backend[1].servers.iteritems() %}
server {{ server[1].name }} {{ server[1].host }}:{{ server[1].port }} {{ server[1].check }}{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}

View File

@ -48,6 +48,7 @@ haproxy:
frontend1:
name: www-http
bind: "*:80"
redirect: scheme https if !{ ssl_fc }
reqadd:
- "X-Forwarded-Proto:\\ http"
default_backend: www-backend