vhost: add support for locations, headers, and responds
This commit is contained in:
@@ -6,18 +6,30 @@
|
||||
marker: "# {mark} ANSIBLE MANAGED BLOCK {{ vhost_id }}"
|
||||
block: |
|
||||
{{ vhost_domains | join(' ') }} {
|
||||
{% if vhost_type == 'reverse_proxy' %}
|
||||
reverse_proxy {{ proxy_target_protocol }}://{{ proxy_target_host }}:{{ proxy_target_port }} {
|
||||
{% if proxy_target_protocol == 'https' and proxy_target_host == 'localhost' %}
|
||||
transport http {
|
||||
tls_insecure_skip_verify
|
||||
{% for location in vhost_locations_all %}
|
||||
handle {{ location.path }} {
|
||||
{% for header in location.headers | dict2items %}
|
||||
header {{ header.key }} `{{ header.value }}`
|
||||
{% endfor %}
|
||||
{% if location.type == 'reverse_proxy' %}
|
||||
reverse_proxy {{ location.proxy_target_protocol }}://{{ location.proxy_target_host }}:{{ location.proxy_target_port }} {
|
||||
{% if location.proxy_target_protocol == 'https' and location.proxy_target_host == 'localhost' %}
|
||||
transport http {
|
||||
tls_insecure_skip_verify
|
||||
}
|
||||
{% endif %}
|
||||
}
|
||||
{% endif %}
|
||||
{% elif location.type == 'redirect' %}
|
||||
redir {{ location.redirect_target }}{{ '{uri}' if location.redirect_preserve_path }} {{ location.redirect_type }}
|
||||
{% elif location.type == 'respond' %}
|
||||
{% if location.respond_content_type == 'json' %}
|
||||
respond `{{ location.respond_content | to_json }}`
|
||||
{% else %}
|
||||
respond `{{ location.respond_content }}`
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
}
|
||||
{% endif %}
|
||||
{% if vhost_type == 'redirect' %}
|
||||
redir {{ redirect_target }} {{ redirect_type }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
}
|
||||
validate: 'caddy validate --config %s --adapter caddyfile'
|
||||
backup: true
|
||||
|
||||
Reference in New Issue
Block a user