{% extends "default.conf.j2" %}
{% block nginx_tpl_block_index %}
{% endblock %}
{% block nginx_tpl_block_location %}
{% if (item.location is defined and item.location) or (item.location_list is defined and item.location_list) %}
{%   if item.location_list is defined and item.location_list %}
{{ print_location_list(item.location_list) }}
{%   endif %}
{%   if item.location is defined and item.location %}
{{ print_location(item.location, item.location_allow, item.location_referers, item.location_deny) }}
{%   endif %}
{% else %}
        location {{ item.proxy_location if item.proxy_location|d() else "/" }} {
{%   if item.proxy_headers is undefined or item.proxy_headers | bool %}
                proxy_set_header Host              $host;
                proxy_set_header X-Real-IP         $remote_addr;
                proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
{%     if not (item.redirect_to_ssl|d(True) | bool) %}
                set $X_Forwarded_Proto "http";
                set $X_Forwarded_Port 80;
                if ($https) {
                        set $X_Forwarded_Proto "https";
                        set $X_Forwarded_Port 443;
                }
                proxy_set_header X-Forwarded-Proto $X_Forwarded_Proto;
                proxy_set_header X-Forwarded-Port $X_Forwarded_Port;
{%     else %}
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Port  {{ "443" if (nginx_tpl_ssl|d() and nginx_tpl_ssl | bool) else "80" }};
{%     endif %}
{%   elif item.proxy_headers|d() %}
{{ item.proxy_headers | indent(16, true) | regex_replace("(?m)^\s*$", "") }}
{%   endif %}
{%   if item.proxy_options|d() and item.proxy_options %}
{{ item.proxy_options | indent(16, true) | regex_replace("(?m)^\s*$", "") }}
{%   endif %}
                proxy_pass {{ item.proxy_pass }};
        }

{% endif %}
{% endblock %}
