# Nginx and unix user directories

Is it possible to configure nginx so that domain/~user is proxied to a port set aside for that user.

Then the user can run another instance of nginx or unicorn on that port.

Is that possible? I would like a database which controls the user to port number relationship though.

-

## migrated from superuser.comMar 21 '11 at 13:52

This question came from our site for computer enthusiasts and power users.

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/;

-
is that like a c switch statement? –  Joseph Le Brech Mar 21 '11 at 14:27
Not sure what you mean, are you referring to the example provided in the link to map documentation? –  zarkdav Mar 21 '11 at 14:29
yes i meant the example in the document is mapping urls to folders? am i right? i could map ~users to sockets in the users home directory? –  Joseph Le Brech Mar 21 '11 at 14:31
No, the example in the documentation is showing how to redirect different paths to different hosts. –  zarkdav Mar 21 '11 at 14:47
i understand this now, thanks :) –  Joseph Le Brech Mar 21 '11 at 15:16