{% block server_redirect %}
{% if item.server_name_redirect is defined %}
server {
    listen       {{ item.listen | default('80') }};
    server_name  {{ item.server_name_redirect }};
    return       301 $scheme://{{ item.server_name.split(' ')[0] }}$request_uri;
}
{% endif %}
{% endblock %}

server {
    {% block server_begin %}{% endblock %}

    {% block server_basic -%}
    listen {{ item.listen | default('80') }};

{% if item.server_name is defined %}
    server_name {{ item.server_name }};
{% endif %}

{% if item.root is defined %}
    root {{ item.root }};
{% endif %}

    index {{ item.index | default('index.html index.htm') }};

{% if item.error_page is defined %}
    error_page {{ item.error_page }};
{% endif %}
{% if item.access_log is defined %}
    access_log {{ item.access_log }};
{% endif %}
{% if item.error_log is defined %}
    error_log {{ item.error_log }} error;
{% endif %}

{% if item.return is defined %}
    return {{ item.return }};
{% endif %}
    {% endblock %}

    {% block server_end %}{% endblock %}

{% if item.extra_parameters is defined %}
    {{ item.extra_parameters|indent(4) }}
{% endif %}
}
