{# upstream block #}
{%- macro upstream(name) %}
upstream {{ name }} {
{%- for serv in varargs %}
    server {{ serv }};
{%- endfor %}
    keepalive 5;
    fair;
}
{%- endmacro %}

{# server block #}
{% macro server(data) -%}
server {
    {{ caller()|indent }}
}
{%- endmacro %}

{# location block #}
{% macro location(pattern, op='') -%}
location {%- if op %} {{ op }}{% endif %} {{ pattern.replace('"', '\\"') }} {
    {{ caller()|indent }}
}
{%- endmacro %}

{% macro proxy_pass(proxy_pass) -%}
proxy_set_header  Host       $Host;
proxy_set_header  X-Real-IP  $remote_addr;
proxy_pass  {{ proxy_pass }};
{%- endmacro %}

{# upstream block #}
{% macro upstream(name) %}
upstream {{ name }} {
{%- for serv in varargs %}
    server {{ serv }};
{%- endfor %}
    keepalive 5;
    fair;
}
{%- endmacro %}

{# listen stat #}
{% macro listen(port, is_default_server=False, is_ssl=False) -%}
listen {{ port }}{% if is_default_server %} default_server{% endif %}{% if is_ssl %} ssl{% endif %};
{%- endmacro %}

{# server_name stat #}
{% macro server_name() -%}
server_name {% for name in varargs %} {{ name }}{% endfor %};
{%- endmacro %}

{# ssl stat #}
{% macro ssl(name) -%}
ssl_certificate {{ name }}.chained.crt;
ssl_certificate_key {{ name }}.key;
{%- endmacro %}

{# alias stat #}
{% macro alias(path) -%}
alias {{ path }};
{%- endmacro %}

{# root stat #}
{% macro root(path) -%}
root {{ path }};
{%- endmacro %}

{# include stat #}
{% macro include(module) -%}
include {{ module }};
{%- endmacro %}
