#jinja2: lstrip_blocks: True {{ ansible_managed | comment }} {% if item.upstreams is defined and item.upstreams %} {% for upstream in item.upstreams %} upstream {{ upstream.name }} { {% for upserver in upstream.servers %} server {{ upserver }}; {% endfor %} } {% endfor %} {% endif %} {% for server in item.servers %} server { listen {{ server.port }}{{ ' ssl' if server.tls is defined and server.tls else '' }}; {% if not server.server_name is string and server.server_name is iterable %} server_name {{ server.server_name | join(" ") }}; {% else %} server_name {{ server.server_name }}; {% endif %} {% if server.tls is defined and server.tls %} ssl_certificate {{ server.tls.cert }}; ssl_certificate_key {{ server.tls.key }}; {% 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 %} {% if server.send_timeout is defined and server.send_timeout %} send_timeout {{ server.send_timeout }}; {% endif %} {% if server.custom_options is defined and server.custom_options %} {% for inline_option in server.custom_options %} {{ inline_option }}{{ "" if inline_option.startswith("if ") else ";" }} {% endfor %} {% endif %} {% for location in server.locations %} location {{ location.match }} { {% 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.add_headers is defined and location.add_headers %} include /etc/nginx/conf.d/header.conf; {% for add in location.add_headers %} add_header {{ add.name }} {{ add.value }}{{ " always" if add.always | default(True) | bool else "" }}; {% endfor %} {% 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 %} {% 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 %} {% if location.proxy_intercept_errors is defined and location.proxy_intercept_errors %} proxy_intercept_errors {{ location.proxy_intercept_errors }}; {% endif %} {% 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 %} proxy_ignore_headers {{ ignore | join(" ") }}; {% endif %} {% endif %} {% if location.custom_options is defined and location.custom_options %} {% for inline_option in location.custom_options %} {{ inline_option }}{{ "" if inline_option.startswith("if ") else ";" }} {% endfor %} {% endif %} } {% endfor %} {% 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 }}; {% endif %} {% if error_location.index is defined and error_location.index %} index {{ error_location.index }}; {% endif %} {% if error_location.custom_options is defined and error_location.custom_options %} {% for inline_option in error_location.custom_options %} {{ inline_option }}{{ "" if inline_option.startswith("if ") else ";" }} {% endfor %} {% endif %} } {% endfor %} {% endif %} } {% endfor %}