{% for redirect in redirects %}
{% if redirect.map is defined %}
map $uri ${{ redirect.map | hash('md5') }} {
    default "";
    include {{ redirect.map }};
}

{% endif %}
server {
    listen       80;
    listen       [::]:80;
    listen       443 ssl http2;
    listen       [::]:443 ssl http2;
    server_name  {{ redirect.domain }};

    access_log   /var/log/nginx/{{ redirect.domain }}/access.log reduced;
    access_log   /var/log/nginx/{{ redirect.domain }}/access.log.json json_reduced;
    error_log    /var/log/nginx/{{ redirect.domain }}/error.log;

    ssl_certificate      /etc/letsencrypt/live/{{ redirect.domain }}/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/{{ redirect.domain }}/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/{{ redirect.domain }}/chain.pem;

    include snippets/letsencrypt.conf;

    location / {
        {% if redirect.map is defined %}
        if (${{ redirect.map | hash('md5') }} != "") {
             return {{ redirect.type }} ${{ redirect.map | hash('md5') }};
        }
        {% endif %}
        return {{ redirect.type }} {{ redirect.to }};
    }
}
{% endfor %}
