{% if item.server_name_redirect is defined %}
server {
    listen       80;
    server_name  {{ item.server_name_redirect }};
    return       301 http://{{ item.server_name }}$request_uri;
}
{% endif %}

server {
    listen {{ item.listen | default("80") }};

    server_name {{ item.server_name }};
    error_log /var/log/nginx/error.log info;
    root {{ item.root }};
    index index.php index.html index.htm;

{% if item.is_php is defined and item.is_php %}
    location / {
        try_files $uri $uri/ = 404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    # Use fastcgi for all php files.
    location ~ \.php$ {
        # Secure *.php files.
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:{{ nginx_php_fpm }};
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_read_timeout 120;
        include fastcgi_params;
    }
{% endif %}
}
