Hi, is there some way to setup rails application to run more virtual domains? I want to have one running instance of rails application with one root directory and one set of source files. But to be able to serve more domains, eg: example.com, music.example.com, blog.example.com, etc... I have found that request object have some basic methods to support it, but I can imagine only one possible way of doing this, which involves some rewrite rules of lighttpd, and a lot of ugly hacking of url generation. Has anybody successfully solved this problem in more elegant way? Thanx a lot. RK
On Aug 10, 2005, at 7:42 AM, Rastislav Kassak wrote:> Hi, > > is there some way to setup rails application to run more virtual > domains? > I want to have one running instance of rails application with one root > directory and one set of source files. But to be able to serve more > domains, eg: > example.com, music.example.com, blog.example.com, etc... > > I have found that request object have some basic methods to support > it, but I can imagine only one possible way of doing this, which > involves some rewrite rules of lighttpd, and a lot of ugly hacking of > url generation. >You shouldn''t have to do that much "ugly hacking" of url generation, since the url_for-derived methods all have "path_only" set by default--they will not try to go to a specific domain. An alternative method (that may not be resource-friendly) is to create several symlink files to your dispatch.fcgi file, e.g.: music_example_com.fcgi -> dispatch.fcgi blog_example_com.fcgi -> dispatch.fcgi etc. And then use separate FastCgiServer directives to load each of those files.> Has anybody successfully solved this problem in more elegant way? >I''d be interested to see some other thoughts, too. Duane Johnson (canadaduane)
What I hear your trying to do really has nothing to do with rails. Just tell apache/lighttpd the same exact settings for all your domains. If you dont use virtualhost directives in your config then ALL hostnames pointing to the ip apache/lighttpd are listening will go to the same exact application -- the default. if you are using apache you can use the VirtualAlias (i think thats it) directive in your VirtualHost block. in lighttpd you can use a generic regex to match all the hostnames (or maybe there is an even better way.) On 8/12/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Aug 10, 2005, at 7:42 AM, Rastislav Kassak wrote: > > > Hi, > > > > is there some way to setup rails application to run more virtual > > domains? > > I want to have one running instance of rails application with one root > > directory and one set of source files. But to be able to serve more > > domains, eg: > > example.com, music.example.com, blog.example.com, etc... > > > > I have found that request object have some basic methods to support > > it, but I can imagine only one possible way of doing this, which > > involves some rewrite rules of lighttpd, and a lot of ugly hacking of > > url generation. > > > > You shouldn''t have to do that much "ugly hacking" of url generation, > since the url_for-derived methods all have "path_only" set by > default--they will not try to go to a specific domain. > > An alternative method (that may not be resource-friendly) is to > create several symlink files to your dispatch.fcgi file, e.g.: > music_example_com.fcgi -> dispatch.fcgi > blog_example_com.fcgi -> dispatch.fcgi > etc. > > And then use separate FastCgiServer directives to load each of those > files. > > > Has anybody successfully solved this problem in more elegant way? > > > I''d be interested to see some other thoughts, too. > > Duane Johnson > (canadaduane) > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Maybe I didn''t explain it enough. I don''t want to serve same content on http://music.example.com/path/to/content and http://movies.example.com/path/to/content. I can imagine such a solution, that routes will be set up with domain names also. map.connect ["domain1", "domain2"], "path/to/content", :controller => "controller1" map.connect ["domain3"], "path/to/content", :controller => "controller2" And to have domain name in parameters of controller - as I recall, It should be accessible already. And contruction of URLs could then contain :domain parameter to override. link_to "text", :domain => "domain2", ... (Well, I didn''t investigate it enough to make sure this call is really useful. :)) On 8/12/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What I hear your trying to do really has nothing to do with rails. > > Just tell apache/lighttpd the same exact settings for all your > domains. If you dont use virtualhost directives in your config then > ALL hostnames pointing to the ip apache/lighttpd are listening will go > to the same exact application -- the default. > > if you are using apache you can use the VirtualAlias (i think thats > it) directive in your VirtualHost block. > > in lighttpd you can use a generic regex to match all the hostnames (or > maybe there is an even better way.) > > > On 8/12/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Aug 10, 2005, at 7:42 AM, Rastislav Kassak wrote: > > > > > Hi, > > > > > > is there some way to setup rails application to run more virtual > > > domains? > > > I want to have one running instance of rails application with one root > > > directory and one set of source files. But to be able to serve more > > > domains, eg: > > > example.com, music.example.com, blog.example.com, etc... > > > > > > I have found that request object have some basic methods to support > > > it, but I can imagine only one possible way of doing this, which > > > involves some rewrite rules of lighttpd, and a lot of ugly hacking of > > > url generation. > > > > > > > You shouldn''t have to do that much "ugly hacking" of url generation, > > since the url_for-derived methods all have "path_only" set by > > default--they will not try to go to a specific domain. > > > > An alternative method (that may not be resource-friendly) is to > > create several symlink files to your dispatch.fcgi file, e.g.: > > music_example_com.fcgi -> dispatch.fcgi > > blog_example_com.fcgi -> dispatch.fcgi > > etc. > > > > And then use separate FastCgiServer directives to load each of those > > files. > > > > > Has anybody successfully solved this problem in more elegant way? > > > > > I''d be interested to see some other thoughts, too. > > > > Duane Johnson > > (canadaduane) > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Juraci Krohling Costa
2005-Aug-14 21:45 UTC
Re: Single rails app on multiple virtual hosts
Well, if you want to use the same app code, using subdomain as parameter, you can use a mix of url rewrite (mod_rewrite) and routes: url before: http://host.domain.com/path/to/controller url after: http://host.domain.com/host/path/to/controller map.connect ''/:host'', .... map.connect ''/:host/:somepath'', ... map.conect ''/host2/:somepath'', ... hth, -- juca juca at jkcosta dot info htt://jkcosta.info Rastislav Kassak wrote:>Maybe I didn''t explain it enough. >I don''t want to serve same content on >http://music.example.com/path/to/content and >http://movies.example.com/path/to/content. > >I can imagine such a solution, that routes will be set up with domain >names also. >map.connect ["domain1", "domain2"], "path/to/content", :controller => >"controller1" >map.connect ["domain3"], "path/to/content", :controller => "controller2" >And to have domain name in parameters of controller - as I recall, It >should be accessible already. > >And contruction of URLs could then contain :domain parameter to override. >link_to "text", :domain => "domain2", ... >(Well, I didn''t investigate it enough to make sure this call is really >useful. :)) > >On 8/12/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>What I hear your trying to do really has nothing to do with rails. >> >>Just tell apache/lighttpd the same exact settings for all your >>domains. If you dont use virtualhost directives in your config then >>ALL hostnames pointing to the ip apache/lighttpd are listening will go >>to the same exact application -- the default. >> >>if you are using apache you can use the VirtualAlias (i think thats >>it) directive in your VirtualHost block. >> >>in lighttpd you can use a generic regex to match all the hostnames (or >>maybe there is an even better way.) >> >> >>On 8/12/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >>>On Aug 10, 2005, at 7:42 AM, Rastislav Kassak wrote: >>> >>> >>> >>>>Hi, >>>> >>>>is there some way to setup rails application to run more virtual >>>>domains? >>>>I want to have one running instance of rails application with one root >>>>directory and one set of source files. But to be able to serve more >>>>domains, eg: >>>>example.com, music.example.com, blog.example.com, etc... >>>> >>>>I have found that request object have some basic methods to support >>>>it, but I can imagine only one possible way of doing this, which >>>>involves some rewrite rules of lighttpd, and a lot of ugly hacking of >>>>url generation. >>>> >>>> >>>> >>>You shouldn''t have to do that much "ugly hacking" of url generation, >>>since the url_for-derived methods all have "path_only" set by >>>default--they will not try to go to a specific domain. >>> >>>An alternative method (that may not be resource-friendly) is to >>>create several symlink files to your dispatch.fcgi file, e.g.: >>>music_example_com.fcgi -> dispatch.fcgi >>>blog_example_com.fcgi -> dispatch.fcgi >>>etc. >>> >>>And then use separate FastCgiServer directives to load each of those >>>files. >>> >>> >>> >>>>Has anybody successfully solved this problem in more elegant way? >>>> >>>> >>>> >>>I''d be interested to see some other thoughts, too. >>> >>>Duane Johnson >>>(canadaduane) >>> >>> >>>_______________________________________________ >>>Rails mailing list >>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>> >>-- >>Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
That''s the solution I was describing as first. But I''m afraid I need to manually contruct URLs. AFAIK, all URLs will be created with /host/ prefix. On 8/14/05, Juraci Krohling Costa <juca-+BZ7G6WzYWuZuzBka8ofvg@public.gmane.org> wrote:> Well, if you want to use the same app code, using subdomain as > parameter, you can use a mix of url rewrite (mod_rewrite) and routes: > > url before: http://host.domain.com/path/to/controller > url after: http://host.domain.com/host/path/to/controller > > map.connect ''/:host'', .... > map.connect ''/:host/:somepath'', ... > map.conect ''/host2/:somepath'', ... > > hth, > -- > juca > juca at jkcosta dot info > htt://jkcosta.info > > Rastislav Kassak wrote: > > >Maybe I didn''t explain it enough. > >I don''t want to serve same content on > >http://music.example.com/path/to/content and > >http://movies.example.com/path/to/content. > > > >I can imagine such a solution, that routes will be set up with domain > >names also. > >map.connect ["domain1", "domain2"], "path/to/content", :controller => > >"controller1" > >map.connect ["domain3"], "path/to/content", :controller => "controller2" > >And to have domain name in parameters of controller - as I recall, It > >should be accessible already. > > > >And contruction of URLs could then contain :domain parameter to override. > >link_to "text", :domain => "domain2", ... > >(Well, I didn''t investigate it enough to make sure this call is really > >useful. :)) > > > >On 8/12/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > >>What I hear your trying to do really has nothing to do with rails. > >> > >>Just tell apache/lighttpd the same exact settings for all your > >>domains. If you dont use virtualhost directives in your config then > >>ALL hostnames pointing to the ip apache/lighttpd are listening will go > >>to the same exact application -- the default. > >> > >>if you are using apache you can use the VirtualAlias (i think thats > >>it) directive in your VirtualHost block. > >> > >>in lighttpd you can use a generic regex to match all the hostnames (or > >>maybe there is an even better way.) > >> > >> > >>On 8/12/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >> > >>>On Aug 10, 2005, at 7:42 AM, Rastislav Kassak wrote: > >>> > >>> > >>> > >>>>Hi, > >>>> > >>>>is there some way to setup rails application to run more virtual > >>>>domains? > >>>>I want to have one running instance of rails application with one root > >>>>directory and one set of source files. But to be able to serve more > >>>>domains, eg: > >>>>example.com, music.example.com, blog.example.com, etc... > >>>> > >>>>I have found that request object have some basic methods to support > >>>>it, but I can imagine only one possible way of doing this, which > >>>>involves some rewrite rules of lighttpd, and a lot of ugly hacking of > >>>>url generation. > >>>> > >>>> > >>>> > >>>You shouldn''t have to do that much "ugly hacking" of url generation, > >>>since the url_for-derived methods all have "path_only" set by > >>>default--they will not try to go to a specific domain. > >>> > >>>An alternative method (that may not be resource-friendly) is to > >>>create several symlink files to your dispatch.fcgi file, e.g.: > >>>music_example_com.fcgi -> dispatch.fcgi > >>>blog_example_com.fcgi -> dispatch.fcgi > >>>etc. > >>> > >>>And then use separate FastCgiServer directives to load each of those > >>>files. > >>> > >>> > >>> > >>>>Has anybody successfully solved this problem in more elegant way? > >>>> > >>>> > >>>> > >>>I''d be interested to see some other thoughts, too. > >>> > >>>Duane Johnson > >>>(canadaduane) > >>> > >>> > >>>_______________________________________________ > >>>Rails mailing list > >>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>>http://lists.rubyonrails.org/mailman/listinfo/rails > >>> > >>> > >>> > >>-- > >>Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >>_______________________________________________ > >>Rails mailing list > >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > >_______________________________________________ > >Rails mailing list > >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
use productized rails. On 8/15/05, Rastislav Kassak <kasou.sk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That''s the solution I was describing as first. > But I''m afraid I need to manually contruct URLs. AFAIK, all URLs will > be created with /host/ prefix. > > On 8/14/05, Juraci Krohling Costa <juca-+BZ7G6WzYWuZuzBka8ofvg@public.gmane.org> wrote: > > Well, if you want to use the same app code, using subdomain as > > parameter, you can use a mix of url rewrite (mod_rewrite) and routes: > > > > url before: http://host.domain.com/path/to/controller > > url after: http://host.domain.com/host/path/to/controller > > > > map.connect ''/:host'', .... > > map.connect ''/:host/:somepath'', ... > > map.conect ''/host2/:somepath'', ... > > > > hth, > > -- > > juca > > juca at jkcosta dot info > > htt://jkcosta.info > > > > Rastislav Kassak wrote: > > > > >Maybe I didn''t explain it enough. > > >I don''t want to serve same content on > > >http://music.example.com/path/to/content and > > >http://movies.example.com/path/to/content. > > > > > >I can imagine such a solution, that routes will be set up with domain > > >names also. > > >map.connect ["domain1", "domain2"], "path/to/content", :controller => > > >"controller1" > > >map.connect ["domain3"], "path/to/content", :controller => "controller2" > > >And to have domain name in parameters of controller - as I recall, It > > >should be accessible already. > > > > > >And contruction of URLs could then contain :domain parameter to override. > > >link_to "text", :domain => "domain2", ... > > >(Well, I didn''t investigate it enough to make sure this call is really > > >useful. :)) > > > > > >On 8/12/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > >>What I hear your trying to do really has nothing to do with rails. > > >> > > >>Just tell apache/lighttpd the same exact settings for all your > > >>domains. If you dont use virtualhost directives in your config then > > >>ALL hostnames pointing to the ip apache/lighttpd are listening will go > > >>to the same exact application -- the default. > > >> > > >>if you are using apache you can use the VirtualAlias (i think thats > > >>it) directive in your VirtualHost block. > > >> > > >>in lighttpd you can use a generic regex to match all the hostnames (or > > >>maybe there is an even better way.) > > >> > > >> > > >>On 8/12/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > > >> > > >>>On Aug 10, 2005, at 7:42 AM, Rastislav Kassak wrote: > > >>> > > >>> > > >>> > > >>>>Hi, > > >>>> > > >>>>is there some way to setup rails application to run more virtual > > >>>>domains? > > >>>>I want to have one running instance of rails application with one root > > >>>>directory and one set of source files. But to be able to serve more > > >>>>domains, eg: > > >>>>example.com, music.example.com, blog.example.com, etc... > > >>>> > > >>>>I have found that request object have some basic methods to support > > >>>>it, but I can imagine only one possible way of doing this, which > > >>>>involves some rewrite rules of lighttpd, and a lot of ugly hacking of > > >>>>url generation. > > >>>> > > >>>> > > >>>> > > >>>You shouldn''t have to do that much "ugly hacking" of url generation, > > >>>since the url_for-derived methods all have "path_only" set by > > >>>default--they will not try to go to a specific domain. > > >>> > > >>>An alternative method (that may not be resource-friendly) is to > > >>>create several symlink files to your dispatch.fcgi file, e.g.: > > >>>music_example_com.fcgi -> dispatch.fcgi > > >>>blog_example_com.fcgi -> dispatch.fcgi > > >>>etc. > > >>> > > >>>And then use separate FastCgiServer directives to load each of those > > >>>files. > > >>> > > >>> > > >>> > > >>>>Has anybody successfully solved this problem in more elegant way? > > >>>> > > >>>> > > >>>> > > >>>I''d be interested to see some other thoughts, too. > > >>> > > >>>Duane Johnson > > >>>(canadaduane) > > >>> > > >>> > > >>>_______________________________________________ > > >>>Rails mailing list > > >>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > >>>http://lists.rubyonrails.org/mailman/listinfo/rails > > >>> > > >>> > > >>> > > >>-- > > >>Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > >>_______________________________________________ > > >>Rails mailing list > > >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > >>http://lists.rubyonrails.org/mailman/listinfo/rails > > >> > > >> > > >> > > >_______________________________________________ > > >Rails mailing list > > >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>