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

93 lines
3.5 KiB
Plaintext
Raw Normal View History

2019-07-17 21:32:11 +00:00
#jinja2: lstrip_blocks: True
{{ ansible_managed | comment }}
{% if item.upstreams is defined and item.upstreams %}
{% for upstream in item.upstreams %}
2019-07-17 21:32:11 +00:00
upstream {{ upstream.name }} {
{% for upserver in upstream.servers %}
2019-07-17 21:32:11 +00:00
server {{ upserver }};
{% endfor %}
}
{% endfor %}
2019-07-17 21:32:11 +00:00
{% endif %}
{% for server in item.servers %}
2019-07-18 20:51:05 +00:00
2019-07-17 21:32:11 +00:00
server {
2019-07-17 22:16:24 +00:00
listen {{ server.port }}{{ ' ssl' if server.tls is defined and server.tls else '' }};
2019-07-27 11:06:38 +00:00
{% if not server.server_name is string and server.server_name is iterable %}
server_name {{ server.server_name | join(" ") }};
{% else %}
2019-07-17 21:32:11 +00:00
server_name {{ server.server_name }};
2019-07-27 11:06:38 +00:00
{% endif %}
2019-07-17 21:32:11 +00:00
{% if server.tls is defined and server.tls %}
2019-07-18 13:55:52 +00:00
2019-07-18 06:59:41 +00:00
ssl_certificate /etc/pki/tls/certs/{{ server.tls.cert }};
ssl_certificate_key /etc/pki/tls/private/{{ server.tls.key }};
2019-07-17 21:32:11 +00:00
{% if server.tls.dhparam is defined %}
ssl_dhparam {{ item.value.ssl.dhparam }};
{% endif %}
{% endif %}
{% if server.tls_redirect | default(False) %}
2019-07-18 14:04:20 +00:00
2019-07-17 21:32:11 +00: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 09:46:44 +00:00
client_max_body_size {{ server.client_max_body_size }};
2019-07-17 21:32:11 +00:00
{% endif %}
2019-08-28 16:32:36 +00:00
{% if server.send_timeout is defined and server.send_timeout %}
send_timeout {{ server.send_timeout }};
2020-05-22 19:22:06 +00:00
{% endif %}
2019-07-17 21:32:11 +00:00
{% for location in server.locations %}
2019-07-17 22:16:24 +00:00
location {{ location.match }} {
2019-07-17 21:32:11 +00: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 20:51:05 +00:00
2019-07-17 21:32:11 +00:00
{% endif %}
{% if location.proxy_pass is defined and location.proxy_pass %}
2019-07-18 21:55:55 +00: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 16:32:36 +00: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 %}
2020-05-22 19:40:03 +00:00
{% if location.proxy_intercept_errors is defined and location.proxy_intercept_errors %}
proxy_intercept_errors {{ location.proxy_intercept_errors }};
{% endif %}
2019-07-18 21:55:55 +00: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 21:32:11 +00:00
{% endif %}
2020-01-18 14:50:29 +00: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 21:32:11 +00: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 %}