default-virtualhost.conf.in 7.59 KB
Newer Older
1 2 3 4 5
{%- 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 -%}
{%- set server_alias_list =  slave_parameter.get('server-alias', '').split() -%}
6
{%- set enable_h2 = ('' ~ slave_parameter.get('enable-http2', slave_parameter['enable_http2_by_default'])).lower() in TRUE_VALUES -%}
7 8 9 10
{%- 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', '') -%}
11 12 13 14 15 16 17 18 19 20 21
{%- set host_list = [slave_parameter.get('custom_domain')] + server_alias_list -%}
{%- 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 %}
{%-   do http_host_list.append('http://%s:%s' % (host, http_port)) %}
{%-   do https_host_list.append('https://%s:%s' % (host, https_port)) %}
{%- endfor %}
{{ https_host_list|join(', ') }} {
  bind {{ local_ipv4 }}
# TODO-Caddy  bind {{ local_ipv6 }}
22 23 24
{%- if ssl_proxy_verify and 'ssl_proxy_ca_crt' in slave_parameter %}
    status 501 /
{%- endif %}
25 26 27 28 29 30 31 32 33 34
  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')) }} {
{%- if slave_parameter.get('path_to_ssl_ca_crt') %}
    clients {{ slave_parameter.get('path_to_ssl_ca_crt') }}
{%- endif %}
  }
# TODO-Caddy   # One Slave two logs
# TODO-Caddy   LogLevel notice
# TODO-Caddy   LogFormat "%h %l %{REMOTE_USER}i %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" combined
  log / {{ slave_parameter.get('access_log') }} {combined}
  errors {{ slave_parameter.get('error_log') }}
35

36 37 38
# TODO-Caddy   SSLProtocol all -SSLv2 -SSLv3
# TODO-Caddy   SSLCipherSuite ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:HIGH:!aNULL:!MD5
# TODO-Caddy   SSLHonorCipherOrder on
39 40

{% if enable_h2 %}
41
# TODO-Caddy   Protocols h2 http/1.1
42 43 44
{% endif -%}

{% if disable_via_header %}
45
# TODO-Caddy   Header unset Via
46 47 48
{% endif -%}

{% if disable_no_cache_header %}
49 50
# TODO-Caddy   RequestHeader unset Cache-Control
# TODO-Caddy   RequestHeader unset Pragma
51 52 53
{% endif -%}

{%- for disabled_cookie in disabled_cookie_list %}
54
# TODO-Caddy {{'  RequestHeader edit Cookie "(^%(disabled_cookie)s=[^;]*; |; %(disabled_cookie)s=[^;]*|^%(disabled_cookie)s=[^;]*$)" ""' % dict(disabled_cookie=disabled_cookie)  }}
55 56 57
{% endfor -%}

{%- if prefer_gzip %}
58
# TODO-Caddy   RequestHeader edit Accept-Encoding "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)" "gzip"
59 60
{% endif %}

61 62 63
{% if slave_type ==  'zope' and backend_url %}
  proxy / {{ backend_url }} {
    transparent
64
    timeout 600s
65 66 67 68 69 70 71 72
{%- if ssl_proxy_verify %}
{%-   if 'ssl_proxy_ca_crt' in slave_parameter %}
# TODO-Caddy   SSLProxyCACertificateFile {{ slave_parameter.get('path_to_ssl_proxy_ca_crt', '') }}
#              Requires https://github.com/mholt/caddy/issues/1550 or "just adding your CA to the system's trust store"
{%-   endif %}
{%- else %}
    insecure_skip_verify
{%- endif %}
73
  }
74
  {% if 'default-path' in slave_parameter %}
75 76 77 78
  redir 301 {
    if {path} is /
    / {scheme}://{host}/{{ slave_parameter.get('default-path') }}
  }
79
  {% endif -%}
80 81 82 83
  rewrite {
    regexp (.*)
    to /VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-https-port', '443') }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1}
  }
84 85 86 87
{% elif slave_type ==  'redirect' and backend_url %}
  redir 302 {
    /  {{ backend_url }}{uri}
  }
88 89
{% else -%}
  {% if 'default-path' in slave_parameter %}
90 91 92 93
  redir 301 {
    if {path} is /
    / {scheme}://{host}/{{ slave_parameter.get('default-path') }}
  }
94
  {% endif -%}
95 96 97 98
  {%- if backend_url %}

  proxy / {{ backend_url }} {
    transparent
99
    timeout 600s
100 101 102 103
{%- if ssl_proxy_verify %}
{%-   if 'ssl_proxy_ca_crt' in slave_parameter %}
# TODO-Caddy   SSLProxyCACertificateFile {{ slave_parameter.get('path_to_ssl_proxy_ca_crt', '') }}
#              Requires https://github.com/mholt/caddy/issues/1550 or "just adding your CA to the system's trust store"
104
{%-   endif %}
105 106 107
{%- else %}
    insecure_skip_verify
{%- endif %}
108 109
  }
  {%-   endif %}
110
{% endif -%}
111
}
112

113 114 115
{{ http_host_list|join(', ') }} {
  bind {{ local_ipv4 }}
# TODO-Caddy  bind {{ local_ipv6 }}
116 117 118
{%- if ssl_proxy_verify and 'ssl_proxy_ca_crt' in slave_parameter %}
    status 501 /
{%- endif %}
119

120 121
  log / {{ slave_parameter.get('access_log') }} {combined}
  errors {{ slave_parameter.get('error_log') }}
122 123

{% if disable_via_header %}
124
# TODO-Caddy   Header unset Via
125
{% endif -%}
126 127 128
# TODO-Caddy   # One Slave two logs
# TODO-Caddy   LogLevel notice
# TODO-Caddy   LogFormat "%h %l %{REMOTE_USER}i %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" combined
129

130 131
# TODO-Caddy   # Remove "Secure" from cookies, as backend may be https
# TODO-Caddy   Header edit Set-Cookie "(?i)^(.+);secure$" "$1"
132 133

{% if enable_h2 %}
134
# TODO-Caddy   Protocols h2 http/1.1
135 136 137
{% endif -%}

{% if disable_no_cache_header %}
138 139
# TODO-Caddy   RequestHeader unset Cache-Control
# TODO-Caddy   RequestHeader unset Pragma
140 141 142
{% endif -%}

{%- for disabled_cookie in disabled_cookie_list %}
143
# TODO-Caddy {{'  RequestHeader edit Cookie "(^%(disabled_cookie)s=[^;]*; |; %(disabled_cookie)s=[^;]*|^%(disabled_cookie)s=[^;]*$)" ""' % dict(disabled_cookie=disabled_cookie)  }}
144 145 146
{% endfor -%}

{%- if prefer_gzip %}
147
# TODO-Caddy   RequestHeader edit Accept-Encoding "(^gzip,.*|.*, gzip,.*|.*, gzip$|^gzip$)" "gzip"
148 149
{% endif %}

150 151
{%- if https_only %}
  redir / https://{host}{uri}
152 153 154 155
{% elif slave_type ==  'redirect' and slave_parameter.get('url', '') %}
  redir 302 {
    /  {{ slave_parameter.get('url', '') }}{uri}
  }
156 157 158
{% elif slave_type ==  'zope' and backend_url %}
  proxy / {{ backend_url }} {
    transparent
159
    timeout 600s
160 161 162 163 164 165 166 167
{%- if ssl_proxy_verify %}
{%-   if 'ssl_proxy_ca_crt' in slave_parameter %}
# TODO-Caddy   SSLProxyCACertificateFile {{ slave_parameter.get('path_to_ssl_proxy_ca_crt', '') }}
#              Requires https://github.com/mholt/caddy/issues/1550 or "just adding your CA to the system's trust store"
{%-   endif %}
{%- else %}
    insecure_skip_verify
{%- endif %}
168
  }
169
  {% if 'default-path' in slave_parameter %}
170 171 172 173
  redir 301 {
    if {path} is /
    / {scheme}://{host}/{{ slave_parameter.get('default-path') }}
  }
174
  {% endif -%}
175 176 177 178
  rewrite {
    regexp (.*)
    to /VirtualHostBase/{scheme}%2F%2F{hostonly}:{{ slave_parameter.get('virtualhostroot-http-port', '80') }}%2F{{ slave_parameter.get('path', '') }}%2FVirtualHostRoot/{1}
  }
179 180
{% else -%}
  {% if 'default-path' in slave_parameter %}
181 182 183 184
  redir 301 {
    if {path} is /
    / {scheme}://{host}/{{ slave_parameter.get('default-path') }}
  }
185
  {% endif -%}
186 187 188
  {%- if slave_parameter.get('url', '') %}
  proxy / {{ slave_parameter.get('url', '') }} {
    transparent
189
    timeout 600s
190 191 192 193
{%- if ssl_proxy_verify %}
{%-   if 'ssl_proxy_ca_crt' in slave_parameter %}
# TODO-Caddy   SSLProxyCACertificateFile {{ slave_parameter.get('path_to_ssl_proxy_ca_crt', '') }}
#              Requires https://github.com/mholt/caddy/issues/1550 or "just adding your CA to the system's trust store"
194
{%-   endif %}
195 196 197
{%- else %}
    insecure_skip_verify
{%- endif %}
198 199
  }
{% endif -%}
200 201 202 203
{% endif -%}
  # If nothing exist : put a nice error
#  ErrorDocument 404 /notfound.html
# Dadiboom
204
}