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

60 lines
2.1 KiB
Plaintext
Raw Normal View History

2019-07-17 21:32:11 +00: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 %}
server {
2019-07-17 22:16:24 +00:00
listen {{ server.port }}{{ ' ssl' if server.tls is defined and server.tls else '' }};
2019-07-17 21:32:11 +00:00
server_name {{ server.server_name }};
{% if server.tls is defined and server.tls %}
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) %}
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 %}
client_max_body_size {{ server.client_max_body_size }};
{% endif %}
{% 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 }};
{% endif %}
{% if location.proxy_pass is defined and location.proxy_pass %}
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 %}
{% for pheader in location.proxy_headers | default([]) %}
proxy_set_header {{ pheader }};
{% endfor %}
{% endif %}
}
{% 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 %}