Proxy to different server based on basic auth username

Hi Nginx community,

I am trying to replace an existing Apache proxy with an equivalent
on using nginx. The current proxy performs an LDAP basic auth and
then using that information with a PHP script redirects to the
correct server that handles that app for the user. Does anyone
have any ideas about how to implement the same funtionality with
nginx + modules?

Cheers,
Ken