upstream omeroweb%(PREFIX_NAME)s {
    server %(FASTCGI_EXTERNAL)s fail_timeout=0;
}

server {
    listen %(HTTPPORT)d;
    server_name %(SERVERNAME)s;

    sendfile on;
    client_max_body_size %(MAX_BODY_SIZE)s;

%(NGINX_SERVER_EXTRA_CONFIG)s

    # maintenance page serve from here
    location @maintenance%(PREFIX_NAME)s {
        root %(ROOT)s/etc/templates/error;
        try_files $uri /maintainance.html =502;
    }

    # weblitz django apps serve media from here
    location %(STATIC_URL)s {
        alias %(STATIC_ROOT)s;
    }

    location @proxy_to_app%(PREFIX_NAME)s {
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_buffering off;

        proxy_pass http://omeroweb%(PREFIX_NAME)s;
    }

    location %(FORCE_SCRIPT_NAME)s {

        error_page 502 @maintenance%(PREFIX_NAME)s;
        # checks for static file, if not found proxy to app
        try_files $uri @proxy_to_app%(PREFIX_NAME)s;
    }

}
