How to hash based on host + path in Varnish?

It doesn't look like the default VCL-provided req object provides a way to get the request path, without query parameters, just the full URL. Thus using some VMODs might help.

You might try using the QueryString VMOD, e.g. (from their docs):

import querystring;

sub vcl_hash {
    if (req.method == "GET" || req.method == "HEAD") {
        hash_data(querystring.remove(req.url));
    }
    else {
        hash_data(req.url);
    }
    hash_data(req.http.host);
    return (lookup);
}

And another nice VMOD, VSLP might also be of interest, given the increased control it provides over backend selection.

Using Varnish 4.1, you might be able to use:

sub vcl_recv {
    if (req.http.host) {
        set req.backend_hint = workers.backend(req.http.host + regsub(req.url, "\?.*$", ""));
    }
    else {
        set req.backend_hint = workers.backend(server.ip + regsub(req.url, "\?.*$", ""));
    }
}

Hope this helps!