default-virtualhost.conf.in 12 KB
Newer Older
1 2 3 4
{%- set TRUE_VALUES = ['y', 'yes', '1', 'true'] %}
{%- set disable_no_cache_header = ('' ~ slave_parameter.get('disable-no-cache-request', '')).lower() in TRUE_VALUES %}
{%- set disable_via_header = ('' ~ slave_parameter.get('disable-via-header', '')).lower() in TRUE_VALUES %}
{%- set prefer_gzip = ('' ~ slave_parameter.get('prefer-gzip-encoding-to-backend', '')).lower() in TRUE_VALUES %}
5 6 7 8
{%- set proxy_append_list = [('', 'Default proxy configuration')] %}
{%- if prefer_gzip %}
{%- do proxy_append_list.append(('prefer-gzip', 'Proxy which always overrides Accept-Encoding to gzip if such is found')) %}
{%- endif %} {#- if prefer_gzip #}
9 10 11 12 13 14
{%- set server_alias_list =  slave_parameter.get('server-alias', '').split() %}
{%- set enable_h2 = ('' ~ slave_parameter.get('enable-http2', slave_parameter['enable_http2_by_default'])).lower() in TRUE_VALUES %}
{%- set ssl_proxy_verify = ('' ~ slave_parameter.get('ssl-proxy-verify', '')).lower() in TRUE_VALUES %}
{%- set disabled_cookie_list =  slave_parameter.get('disabled-cookie-list', '').split() %}
{%- set https_only = ('' ~ slave_parameter.get('https-only', '')).lower() in TRUE_VALUES %}
{%- set slave_type = slave_parameter.get('type', '') %}
15 16 17 18
{%- set host_list = server_alias_list %}
{%- if slave_parameter.get('custom_domain') not in host_list %}
{%-   do host_list.append(slave_parameter.get('custom_domain')) %}
{%- endif %}
19 20 21 22
{%- set backend_url = slave_parameter.get('https-url', slave_parameter.get('url', '')) %}
{%- set http_host_list = [] %}
{%- set https_host_list = [] %}
{%- for host in host_list %}
23 24
{%-   do http_host_list.append('http://%s:%s' % (host, slave_parameter['http_port'] )) %}
{%-   do https_host_list.append('https://%s:%s' % (host, slave_parameter['https_port'] )) %}
25
{%- endfor %} {#- for host in host_list #}
26
{%- set default_path = slave_parameter.get('default-path', '') | urlencode %}
27 28

# SSL enabled hosts
29
{{ https_host_list|join(', ') }} {
30
  bind {{ slave_parameter['local_ipv4'] }}
31 32
  # Compress the output
  gzip
33
  tls {{ slave_parameter.get('path_to_ssl_crt', slave_parameter.get('login_certificate')) }} {{ slave_parameter.get('path_to_ssl_key', slave_parameter.get('login_key')) }} {
34 35
{%- if enable_h2 %}
    # Allow HTTP2
36
    alpn h2 http/1.1
37
{%- else %} {#- if enable_h2 #}
38
    # Disallow HTTP2
39
    alpn http/1.1
40 41
{%- endif %} {#- if enable_h2 #}
  } {# tls #}
42
  log / {{ slave_parameter.get('access_log') }} "{remote} {>REMOTE_USER} [{when}] \"{method} {uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\" {latency_ms}"
43
  errors {{ slave_parameter.get('error_log') }}
44

45
{%- if prefer_gzip and not (slave_type == 'zope' and backend_url) %}
46 47 48 49
  rewrite {
    if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
    to /prefer-gzip{uri}
  }
50
{%- endif %} {#- if prefer_gzip and not (slave_type == 'zope' and backend_url) #}
51

52 53
{%- if slave_type ==  'zope' and backend_url %}
  # Zope configuration
54 55 56 57 58 59 60
{%-   for (proxy_name, proxy_comment) in proxy_append_list %}
  # {{ proxy_comment }}
  proxy /{{ proxy_name }} {{ backend_url }} {
{%-     if proxy_name == 'prefer-gzip' %}
    without /prefer-gzip
    header_upstream Accept-Encoding gzip
{%-     endif %} {#-     if proxy_name == 'prefer-gzip' #}
61 62
    # As backend is trusting REMOTE_USER header unset it always
    header_upstream -REMOTE_USER
63 64 65 66
{%- for disabled_cookie in disabled_cookie_list %}
    # Remove cookie {{ disabled_cookie }} from client Cookies
    header_upstream Cookie "(.*)(^{{ disabled_cookie }}=[^;]*; |; {{ disabled_cookie }}=[^;]*|^{{ disabled_cookie }}=[^;]*$)(.*)" "$1 $3"
{%- endfor %} {#- for disabled_cookie in disabled_cookie_list #}
67

68
{%-   if disable_via_header %}
69
    header_downstream -Via
70
{%-   endif %} {#-   if disable_via_header #}
71

72
{%-   if disable_no_cache_header %}
73 74
    header_upstream -Cache-Control
    header_upstream -Pragma
75
{%-   endif %} {#-   if disable_no_cache_header #}
76
    transparent
77
    timeout 600s
78
{%-   if ssl_proxy_verify %}
79 80 81
{%-     if 'path_to_ssl_proxy_ca_crt' in slave_parameter %}
    ca_certificates {{ slave_parameter['path_to_ssl_proxy_ca_crt'] }}
{%-     endif %} {#-     if 'path_to_ssl_proxy_ca_crt' in slave_parameter #}
82
{%-   else %} {#-   if ssl_proxy_verify #}
83
    insecure_skip_verify
84 85
{%-   endif %} {#-   if ssl_proxy_verify #}
  } {# proxy #}
86
{%-   endfor %} {#-   for (proxy_name, proxy_comment) in proxy_append_list #}
87
  {%- if default_path %}
88 89
  redir 301 {
    if {path} is /
90
    / {scheme}://{host}/{{ default_path }}
91
  } {# redir #}
92
  {%- endif %} {#- if default_path #}
93 94 95 96 97 98 99
{%- if prefer_gzip  %}
  rewrite {
    regexp (.*)
    if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
    to /prefer-gzip/VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-https-port', '443') | int }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1}
  }
{%- else %}
100 101
  rewrite {
    regexp (.*)
102
    to /VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-https-port', '443') | int }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1}
103
  } {# rewrite #}
104
{%- endif %} {#- if prefer_gzip #}
105
{%- elif slave_type ==  'redirect' and backend_url %} {#- if slave_type ==  'zope' and backend_url #}
106
  # Redirect configuration
107 108
  redir 302 {
    /  {{ backend_url }}{uri}
109 110
  } {# redir #}
{%- else %} {#- if slave_type ==  'zope' and backend_url #}
111
  # Default configuration
112
{%-   if default_path %}
113 114
  redir 301 {
    if {path} is /
115
    / {scheme}://{host}/{{ default_path }}
116
  }  {# redir #}
117
{%-   endif %} {#-   if default_path #}
118
{%-   if backend_url %}
119

120 121 122 123 124 125 126
{%-   for (proxy_name, proxy_comment) in proxy_append_list %}
  # {{ proxy_comment }}
  proxy /{{ proxy_name }} {{ backend_url }} {
{%-     if proxy_name == 'prefer-gzip' %}
    without /prefer-gzip
    header_upstream Accept-Encoding gzip
{%-     endif %} {#-     if proxy_name == 'prefer-gzip' #}
127 128
    # As backend is trusting REMOTE_USER header unset it always
    header_upstream -REMOTE_USER
129 130 131 132
{%- for disabled_cookie in disabled_cookie_list %}
    # Remove cookie {{ disabled_cookie }} from client Cookies
    header_upstream Cookie "(.*)(^{{ disabled_cookie }}=[^;]*; |; {{ disabled_cookie }}=[^;]*|^{{ disabled_cookie }}=[^;]*$)(.*)" "$1 $3"
{%- endfor %} {#- for disabled_cookie in disabled_cookie_list #}
133

134
{%-     if disable_via_header %}
135
    header_downstream -Via
136
{%-     endif %} {#-     if disable_via_header #}
137

138
{%-     if disable_no_cache_header %}
139 140
    header_upstream -Cache-Control
    header_upstream -Pragma
141
{%-     endif %} {#-     if disable_no_cache_header #}
142
    transparent
143
    timeout 600s
144
{%-     if ssl_proxy_verify %}
145 146 147
{%-       if 'path_to_ssl_proxy_ca_crt' in slave_parameter %}
    ca_certificates {{ slave_parameter['path_to_ssl_proxy_ca_crt'] }}
{%-       endif %} {#-       if 'path_to_ssl_proxy_ca_crt' in slave_parameter #}
148
{%-     else %} {#-     if ssl_proxy_verify #}
149
    insecure_skip_verify
150 151
{%-     endif %} {#-     if ssl_proxy_verify #}
  }  {# proxy #}
152
{%-    endfor %} {#-   for (proxy_name, proxy_comment) in proxy_append_list #}
153 154 155
{%-   endif %} {#-   if backend_url #}
{%- endif %} {#- if slave_type ==  'zope' and backend_url #}
}  {# https_host_list|join(', ') #}
156

157
# SSL-disabled hosts
158
{{ http_host_list|join(', ') }} {
159
  bind {{ slave_parameter['local_ipv4'] }}
160 161
  # Compress the output
  gzip
162

163
  log / {{ slave_parameter.get('access_log') }} "{remote} {>REMOTE_USER} [{when}] \"{method} {uri} {proto}\" {status} {size} \"{>Referer}\" \"{>User-Agent}\" {latency_ms}"
164
  errors {{ slave_parameter.get('error_log') }}
165

166
{%- if prefer_gzip and not (slave_type == 'zope' and backend_url) %}
167 168 169 170
  rewrite {
    if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
    to /prefer-gzip{uri}
  }
171
{%- endif %} {#- if prefer_gzip and not (slave_type == 'zope' and backend_url) #}
172

173 174
{%- if https_only %}
  # Enforced redirection to SSL-enabled host
175
  redir / https://{host}{uri}
176
{%- elif slave_type ==  'redirect' and slave_parameter.get('url', '') %} {#- if https_only #}
177
  # Redirect configuration
178 179
  redir 302 {
    /  {{ slave_parameter.get('url', '') }}{uri}
180 181
  } {# redir #}
{%- elif slave_type ==  'zope' and backend_url %} {#- if https_only #}
182
  # Zope configuration
183 184 185 186 187 188 189
{%-   for (proxy_name, proxy_comment) in proxy_append_list %}
  # {{ proxy_comment }}
  proxy /{{ proxy_name }} {{ backend_url }} {
{%-     if proxy_name == 'prefer-gzip' %}
    without /prefer-gzip
    header_upstream Accept-Encoding gzip
{%-     endif %} {#-     if proxy_name == 'prefer-gzip' #}
190 191
    # As backend is trusting REMOTE_USER header unset it always
    header_upstream -REMOTE_USER
192 193 194 195
{%- for disabled_cookie in disabled_cookie_list %}
    # Remove cookie {{ disabled_cookie }} from client Cookies
    header_upstream Cookie "(.*)(^{{ disabled_cookie }}=[^;]*; |; {{ disabled_cookie }}=[^;]*|^{{ disabled_cookie }}=[^;]*$)(.*)" "$1 $3"
{%- endfor %} {#- for disabled_cookie in disabled_cookie_list #}
196

197
{%-   if disable_via_header %}
198
    header_downstream -Via
199
{%-   endif %} {#-   if disable_via_header #}
200

201
{%-   if disable_no_cache_header %}
202 203
    header_upstream -Cache-Control
    header_upstream -Pragma
204
{%-   endif %} {#-   if disable_no_cache_header #}
205
    transparent
206
    timeout 600s
207
{%-   if ssl_proxy_verify %}
208 209 210
{%-     if 'path_to_ssl_proxy_ca_crt' in slave_parameter %}
    ca_certificates {{ slave_parameter['path_to_ssl_proxy_ca_crt'] }}
{%-     endif %} {#-     if 'path_to_ssl_proxy_ca_crt' in slave_parameter #}
211
{%-   else %} {#-   if ssl_proxy_verify #}
212
    insecure_skip_verify
213 214
{%-   endif %} {#-   if ssl_proxy_verify #}
  } {# proxy #}
215
{%- endfor %} {#-   for (proxy_name, proxy_comment) in proxy_append_list #}
216
{%-   if default_path %}
217 218
  redir 301 {
    if {path} is /
219
    / {scheme}://{host}/{{ default_path }}
220
  } {# redir #}
221
{%-   endif %} {#-   if default_path #}
222 223 224 225 226 227 228
{%- if prefer_gzip  %}
  rewrite {
    regexp (.*)
    if {>Accept-Encoding} match "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)"
    to /prefer-gzip/VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-http-port', '80') | int }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1}
  }
{%- else %}
229 230
  rewrite {
    regexp (.*)
231
    to /VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-http-port', '80') | int }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1}
232
  } {# rewrite #}
233
{% endif %} {#- if prefer_gzip #}
234
{%- else %} {#- if https_only #}
235
  # Default configuration
236
{%-   if default_path %}
237 238
  redir 301 {
    if {path} is /
239
    / {scheme}://{host}/{{ default_path }}
240
  } {# redir #}
241
{%-   endif %} {#-   if default_path #}
242
{%-   if slave_parameter.get('url', '') %}
243 244 245 246 247 248 249
{%-   for (proxy_name, proxy_comment) in proxy_append_list %}
  # {{ proxy_comment }}
  proxy /{{ proxy_name }} {{ slave_parameter.get('url', '') }} {
{%-     if proxy_name == 'prefer-gzip' %}
    without /prefer-gzip
    header_upstream Accept-Encoding gzip
{%-     endif %} {#-     if proxy_name == 'prefer-gzip' #}
250 251
    # As backend is trusting REMOTE_USER header unset it always
    header_upstream -REMOTE_USER
252 253 254 255
{%- for disabled_cookie in disabled_cookie_list %}
    # Remove cookie {{ disabled_cookie }} from client Cookies
    header_upstream Cookie "(.*)(^{{ disabled_cookie }}=[^;]*; |; {{ disabled_cookie }}=[^;]*|^{{ disabled_cookie }}=[^;]*$)(.*)" "$1 $3"
{%- endfor %} {#- for disabled_cookie in disabled_cookie_list #}
256

257
{%-     if disable_via_header %}
258
    header_downstream -Via
259
{%-     endif %} {#-     if disable_via_header #}
260

261
{%-     if disable_no_cache_header %}
262 263
    header_upstream -Cache-Control
    header_upstream -Pragma
264
{%-     endif %} {#-     if disable_no_cache_header #}
265
    transparent
266
    timeout 600s
267
{%-     if ssl_proxy_verify %}
268 269 270
{%-       if 'path_to_ssl_proxy_ca_crt' in slave_parameter %}
    ca_certificates {{ slave_parameter['path_to_ssl_proxy_ca_crt'] }}
{%-       endif %} {#-       if 'path_to_ssl_proxy_ca_crt' in slave_parameter #}
271
{%-     else %} {#-     if ssl_proxy_verify #}
272
    insecure_skip_verify
273 274
{%-     endif %} {#-     if ssl_proxy_verify #}
  } {# proxy #}
275
{%-    endfor %} {#-   for (proxy_name, proxy_comment) in proxy_append_list #}
276 277 278
{%-   endif %} {#-   if slave_parameter.get('url', '') #}
{%- endif %} {#- if https_only #}
} {# http_host_list|join(', ') #}