You could use a combination of nginx map and rewrite modules. You would need a script to generate the map configuration out of the database, though.
The target configuration would look like this:
map $uri $new {
default http://www.domain.com/;
include /path/to/usermap.txt;
}
server {
server_name www.domain.com;
rewrite ^ $new redirect;
}
With /path/to/usermap.txt being generated by a script with an output similar to this:
# automatically generated by a script
/~alice http://www.domain.com:8001/;
/~bob http://www.domain.com:8002/;
/~chuck http://www.domain.com:8003/;