xoxys.nginx/templates/etc/nginx/sites-available/vhost.j2

89 lines
3.3 KiB
Plaintext
Raw Normal View History

2019-07-17 23:32:11 +02:00
#jinja2: lstrip_blocks: True
{{ ansible_managed | comment }}
{% if item.upstream is defined and item.upstream %}
upstream {{ item.upstream.name }} {
{% for upserver in item.upstream.servers %}
server {{ upserver }};
{% endfor %}
}
{% endif %}
{% for server in item.servers %}
2019-07-18 22:51:05 +02:00
2019-07-17 23:32:11 +02:00
server {
2019-07-18 00:16:24 +02:00
listen {{ server.port }}{{ ' ssl' if server.tls is defined and server.tls else '' }};
2019-07-27 13:06:38 +02:00
{% if not server.server_name is string and server.server_name is iterable %}
server_name {{ server.server_name | join(" ") }};
{% else %}
2019-07-17 23:32:11 +02:00
server_name {{ server.server_name }};
2019-07-27 13:06:38 +02:00
{% endif %}
2019-07-17 23:32:11 +02:00
{% if server.tls is defined and server.tls %}
2019-07-18 15:55:52 +02:00
2019-07-18 08:59:41 +02:00
ssl_certificate /etc/pki/tls/certs/{{ server.tls.cert }};
ssl_certificate_key /etc/pki/tls/private/{{ server.tls.key }};
2019-07-17 23:32:11 +02:00
{% if server.tls.dhparam is defined %}
ssl_dhparam {{ item.value.ssl.dhparam }};
{% endif %}
{% endif %}
{% if server.tls_redirect | default(False) %}
2019-07-18 16:04:20 +02:00
2019-07-17 23:32:11 +02:00
return 301 https://{% if server.tls_redirect_url is defined %}{{ server.tls_redirect_url }}{% else %}$server_name{% endif %}$request_uri;
{% else %}
{% if server.client_max_body_size is defined and server.client_max_body_size %}
2019-07-27 11:46:44 +02:00
client_max_body_size {{ server.client_max_body_size }};
2019-07-17 23:32:11 +02:00
{% endif %}
2019-08-28 18:32:36 +02:00
{% if server.send_timeout is defined and server.send_timeout %}
send_timeout {{ server.send_timeout }};
{% endif %}
2019-07-18 15:55:52 +02:00
2019-07-17 23:32:11 +02:00
{% for location in server.locations %}
2019-07-18 00:16:24 +02:00
location {{ location.match }} {
2019-07-17 23:32:11 +02:00
{% if location.root is defined and location.root %}
root {{ location.root }};
{% endif %}
{% if location.index is defined and location.index %}
index {{ location.index }};
2019-07-18 22:51:05 +02:00
2019-07-17 23:32:11 +02:00
{% endif %}
{% if location.proxy_pass is defined and location.proxy_pass %}
2019-07-18 23:55:55 +02:00
proxy_pass {{ location.proxy_pass }};
{% if location.proxy_http_version is defined and location.proxy_http_version %}
proxy_http_version {{ location.proxy_http_version }};
{% endif %}
2019-08-28 18:32:36 +02:00
{% if location.proxy_buffering is defined and location.proxy_buffering %}
proxy_buffering {{ location.proxy_buffering }};
{% endif %}
{% if location.proxy_connect_timeout is defined and location.proxy_connect_timeout %}
proxy_connect_timeout {{ location.proxy_connect_timeout }};
{% endif %}
{% if location.proxy_read_timeout is defined and location.proxy_read_timeout %}
proxy_read_timeout {{ location.proxy_read_timeout }};
{% endif %}
{% if location.proxy_send_timeout is defined and location.proxy_send_timeout %}
proxy_send_timeout {{ location.proxy_send_timeout }};
{% endif %}
2019-07-18 23:55:55 +02:00
{% if location.proxy_headers is defined and location.proxy_headers %}
{% for pheader in location.proxy_headers %}
proxy_set_header {{ pheader }};
{% endfor %}
{% endif %}
2019-07-17 23:32:11 +02:00
{% endif %}
2020-01-18 15:50:29 +01:00
{% if location.custom_options is defined and location.custom_options %}
{% for inline_option in location.custom_options %}
{{ inline_option }};
{% endfor %}
{% endif %}
2019-07-17 23:32:11 +02:00
}
{% endfor %}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root {{ item.error_page | default("/usr/share/nginx/html") }};
}
{% endif %}
}
{% endfor %}