For the records: I got it working with this config:
foo.domain.tld {
handle {
rewrite /* /foo{uri}
reverse_proxy * http://IP {
header_up Host {host}
header_up X-Real-IP {remote_host}
}
}
}
From my understanding what it does: When a user hits https://foo.domain.tld the block appends foo and reverse proxy that to the IP, so as a result the request gets transformed into http://IP/foo.
Thanks for your answers, which lead eventually to a working solution.