2019-07-17 21:32:11 +00:00
|
|
|
#jinja2: lstrip_blocks: True
|
|
|
|
{{ ansible_managed | comment }}
|
2020-01-20 13:37:38 +00:00
|
|
|
{% if item.upstreams is defined and item.upstreams %}
|
|
|
|
{% for upstream in item.upstreams %}
|
2019-07-17 21:32:11 +00:00
|
|
|
|
2020-01-20 13:37:38 +00:00
|
|
|
upstream {{ upstream.name }} {
|
|
|
|
{% for upserver in upstream.servers %}
|
2019-07-17 21:32:11 +00:00
|
|
|
server {{ upserver }};
|
|
|
|
{% endfor %}
|
|
|
|
}
|
2020-01-20 13:37:38 +00:00
|
|
|
{% 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
|
|
|
|
2020-06-04 21:09:15 +00:00
|
|
|
ssl_certificate {{ server.tls.cert }};
|
|
|
|
ssl_certificate_key {{ 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 %}
|
2021-05-20 13:10:01 +00:00
|
|
|
{% if server.add_headers is defined and server.add_headers %}
|
|
|
|
|
|
|
|
include /etc/nginx/conf.d/header.conf;
|
|
|
|
{% for add in server.add_headers %}
|
|
|
|
add_header {{ add.name }} {{ add.value }}{{ " always" if add.always | default(True) | bool else "" }};
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2020-05-25 08:15:42 +00:00
|
|
|
{% if server.custom_options is defined and server.custom_options %}
|
|
|
|
|
|
|
|
{% for inline_option in server.custom_options %}
|
2020-10-03 11:29:59 +00:00
|
|
|
{{ inline_option }}{{ "" if inline_option.startswith("if ") else ";" }}
|
2020-05-25 08:15:42 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% 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
|
|
|
|
2021-05-20 09:00:24 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if location.add_headers is defined and location.add_headers %}
|
|
|
|
include /etc/nginx/conf.d/header.conf;
|
|
|
|
{% for add in location.add_headers %}
|
2021-05-20 12:47:09 +00:00
|
|
|
add_header {{ add.name }} {{ add.value }}{{ " always" if add.always | default(True) | bool else "" }};
|
2021-05-20 09:00:24 +00:00
|
|
|
{% endfor %}
|
|
|
|
|
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 }};
|
2021-05-31 19:50:13 +00:00
|
|
|
{% if location.proxy_pass_request_body is defined and location.proxy_pass_request_body %}
|
|
|
|
proxy_pass_request_body {{ location.proxy_pass_request_body }};
|
|
|
|
{% endif %}
|
|
|
|
{% if location.proxy_next_upstream is defined and location.proxy_next_upstream %}
|
|
|
|
proxy_next_upstream {{ location.proxy_next_upstream }};
|
|
|
|
{% endif %}
|
|
|
|
{% if location.proxy_redirect is defined and location.proxy_redirect %}
|
|
|
|
proxy_redirect {{ location.proxy_redirect }};
|
|
|
|
{% endif %}
|
2019-07-18 21:55:55 +00:00
|
|
|
{% 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 %}
|
2021-05-31 19:50:13 +00:00
|
|
|
{% if location.proxy_cache_bypass is defined and location.proxy_cache_bypass %}
|
|
|
|
proxy_cache_bypass {{ location.proxy_cache_bypass }};
|
|
|
|
{% endif %}
|
|
|
|
{% if location.proxy_no_cache is defined and location.proxy_no_cache %}
|
|
|
|
proxy_no_cache {{ location.proxy_no_cache }};
|
|
|
|
{% endif %}
|
|
|
|
{% if location.proxy_buffers is defined and location.proxy_buffers %}
|
|
|
|
proxy_buffers {{ location.proxy_buffers }};
|
|
|
|
{% endif %}
|
2021-05-20 09:00:24 +00:00
|
|
|
{% if location.proxy_set_headers is defined and location.proxy_set_headers %}
|
|
|
|
|
|
|
|
{% for set in location.proxy_set_headers %}
|
|
|
|
proxy_set_header {{ set }};
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% if location.proxy_hide_headers is defined and location.proxy_hide_headers %}
|
|
|
|
|
|
|
|
{% for hide in location.proxy_hide_headers %}
|
|
|
|
proxy_hide_header {{ hide }};
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% if location.proxy_ignore_headers is defined and location.proxy_ignore_headers %}
|
2019-07-18 21:55:55 +00:00
|
|
|
|
2021-05-20 13:30:13 +00:00
|
|
|
proxy_ignore_headers {{ location.proxy_ignore_headers | join(" ") }};
|
2019-07-18 21:55:55 +00:00
|
|
|
{% 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 %}
|
2020-10-03 11:56:32 +00:00
|
|
|
{{ inline_option }}{{ "" if inline_option.startswith("if ") else ";" }}
|
2020-01-18 14:50:29 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2019-07-17 21:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{% endfor %}
|
2020-05-25 09:22:18 +00:00
|
|
|
{% for error_location in nginx_error_location %}
|
|
|
|
location {{ error_location.match }} {
|
|
|
|
{% if error_location.root is defined and error_location.root %}
|
|
|
|
root {{ error_location.root }};
|
2020-05-25 09:10:03 +00:00
|
|
|
{% endif %}
|
2020-05-25 09:22:18 +00:00
|
|
|
{% if error_location.index is defined and error_location.index %}
|
|
|
|
index {{ error_location.index }};
|
2020-05-25 09:10:03 +00:00
|
|
|
|
|
|
|
{% endif %}
|
2020-05-25 09:22:18 +00:00
|
|
|
{% if error_location.custom_options is defined and error_location.custom_options %}
|
2020-05-25 09:10:03 +00:00
|
|
|
|
2020-05-25 09:22:18 +00:00
|
|
|
{% for inline_option in error_location.custom_options %}
|
2020-10-03 11:56:32 +00:00
|
|
|
{{ inline_option }}{{ "" if inline_option.startswith("if ") else ";" }}
|
2020-05-25 09:10:03 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
}
|
2020-05-25 09:22:18 +00:00
|
|
|
{% endfor %}
|
2020-05-25 09:33:35 +00:00
|
|
|
{% endif %}
|
2019-07-17 21:32:11 +00:00
|
|
|
}
|
|
|
|
{% endfor %}
|