nginx magic sub domains - help for yoda needed

Go To StackoverFlow.com

0

I am planning to offer some free hosting for ruby development. At the moment I have to manually edit nginx to add sub domains when a user is create to point to his directory /home/$user/www/public

so for user yoda I have something like this

server {
      listen 80;
      server_name yoda.jedi.am;
   root /home/yoda/www/public;   
   passenger_enabled on;
}

Now suppose I add user obione is there anyway to set nginx to automatically server user.jedi.am with root /home/user/www/public and if that is not available to redirect to the main root ?

Thanks

2012-04-03 22:15
by user1212889
this http://pastebin.com/rcf1eiVQ doesn't work : - user1212889 2012-04-03 23:02


0

Try something more like:

    server {
            listen 80;
            server_name ~^(.*)\.jedi\.am$
            if ($hostname ~ ^(.*)\.jedi\.am$) {
                    set $user $1;
            }
            if ( ! -d /home/$user/www/public ) {
                    rewrite . http://jedi.am/ redirect;
            }
            root /home/$user/www/public;
            passenger_enabled on;
    }

Untested, but this or something like it should work.

2012-04-06 22:03
by jmervine