I need to dynamicly set a env var in Apache virtual host setting, ie, differnt domain has different value for the var. I know FCGI can work around this by something like this: FastCgiServer /path/to/dispatch.fcgi -initial-env RAILS_ENV=production [other options]. What about mod_scgi and Zed''s SRR(SCGI Rails Runner)? I searched and read that mod_scgi passes env to scgi server (not sure if env set by SetEnv is passed). But I can''t see it from ENV. ENV only contains environment variables set when SRR was started. Is this achievable? Thanks, Kevin
You can start the runner with -e option to set the mode. There''s a new release coming down this week that will make it easier to let Apache start SRR for you. Of course, after that happens people will then start sending me questions about why Apache starts so many copies of their Rails application. Just can''t win. Zed On Thu, 6 Oct 2005 00:57:07 -0700 K C <born70s-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to dynamicly set a env var in Apache virtual host setting, ie, > differnt domain has different value for the var. > > I know FCGI can work around this by something like this: FastCgiServer > /path/to/dispatch.fcgi -initial-env RAILS_ENV=production [other > options]. > > What about mod_scgi and Zed''s SRR(SCGI Rails Runner)? > > I searched and read that mod_scgi passes env to scgi server (not sure > if env set by SetEnv is passed). But I can''t see it from ENV. ENV > only contains environment variables set when SRR was started. > > Is this achievable? > > Thanks, > Kevin > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Actually I''m not trying to set the mode. All I want is to pass a variable to Rails on the fly according to which site/domain is accessed. I suppose to have *many* sites and each site has a distinct site_id which I want to set via Apache virtual host. Each site may have *multiple domains* (not subdomain) and I found Apache''s SetEnv in virtual host is my best choice. Query site_id from Rails is possible but not that straightforward given the fact that each site has multiple domains and it brings extra complexity and code. I did this in PHP but now seems out of luck with SCGI. To let Apache start SRR is out of the question if I need to host 1000 sites. Any workaround? BTW, SCGI is so easy to setup and admin that I really want to be on it. Thanks Zed for your work! Thanks, Kevin On 10/6/05, Zed A. Shaw <zedshaw-dd7LMGGEL7NBDgjK7y7TUQ@public.gmane.org> wrote:> You can start the runner with -e option to set the mode. There''s a new > release coming down this week that will make it easier to let Apache > start SRR for you. Of course, after that happens people will then > start sending me questions about why Apache starts so many copies of > their Rails application. Just can''t win. > > Zed > > On Thu, 6 Oct 2005 00:57:07 -0700 > K C <born70s-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I need to dynamicly set a env var in Apache virtual host setting, ie, > > differnt domain has different value for the var. > > > > I know FCGI can work around this by something like this: FastCgiServer > > /path/to/dispatch.fcgi -initial-env RAILS_ENV=production [other > > options]. > > > > What about mod_scgi and Zed''s SRR(SCGI Rails Runner)? > > > > I searched and read that mod_scgi passes env to scgi server (not sure > > if env set by SetEnv is passed). But I can''t see it from ENV. ENV > > only contains environment variables set when SRR was started. > > > > Is this achievable? > > > > Thanks, > > Kevin > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails >
After some reading, I don''t think this can be done by mod_scgi and SRR. If I understand right, mod_scgi is client and SRR is server, and the client can''t change the server''s ENV. An alternative is to use mod_rewrite to append the var to the request...but that''s less elegant though :-( and maybe unsecure as anybody can append a site_id=value to the URL to try to fool the server. Anybody any idea? Thanks, Kevin On 10/6/05, K C <born70s-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Actually I''m not trying to set the mode. All I want is to pass a > variable to Rails on the fly according to which site/domain is > accessed. > > I suppose to have *many* sites and each site has a distinct site_id > which I want to set via Apache virtual host. Each site may have > *multiple domains* (not subdomain) and I found Apache''s SetEnv in > virtual host is my best choice. Query site_id from Rails is possible > but not that straightforward given the fact that each site has > multiple domains and it brings extra complexity and code. I did this > in PHP but now seems out of luck with SCGI. > > To let Apache start SRR is out of the question if I need to host 1000 > sites. Any workaround? > > BTW, SCGI is so easy to setup and admin that I really want to be on > it. Thanks Zed for your work! > > Thanks, > Kevin
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 6, 2005, at 1:45 PM, K C wrote:> After some reading, I don''t think this can be done by mod_scgi and > SRR. If I understand right, mod_scgi is client and SRR is server, and > the client can''t change the server''s ENV. > > An alternative is to use mod_rewrite to append the var to the > request...but that''s less elegant though :-( and maybe unsecure as > anybody can append a site_id=value to the URL to try to fool the > server. > > Anybody any idea?How about putting the Site has_many :domains mapping in the db instead of your vhost config? class Site < ActiveRecord::Base has_many :domains end class Domain < ActiveRecord::Base belongs_to :site end class ApplicationController < ActionController::Base attr_reader :site before_filter :find_site_by_domain private def find_site_by_domain domain = Domain.find_by_domain(request.domain) @site = domain.site unless domain.nil? end end Best, jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDRZALAQHALep9HFYRAhDjAJ472RIwvXWTwrQKCHjLEOPMKjh01gCgq1EJ g0YBwu5/ndj+CShdai7Ku4M=1hSu -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 6, 2005, at 1:45 PM, K C wrote:> After some reading, I don''t think this can be done by mod_scgi and > SRR. If I understand right, mod_scgi is client and SRR is server, and > the client can''t change the server''s ENV. > > An alternative is to use mod_rewrite to append the var to the > request...but that''s less elegant though :-( and maybe unsecure as > anybody can append a site_id=value to the URL to try to fool the > server. > > Anybody any idea?Another way is to pass a X-Site-Id HTTP header using a rewrite rule and extract @site = Site.find(headers[''HTTP_X_SITE_ID'']) in a before_filter. Best, jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDRZCKAQHALep9HFYRAqCkAJ4xnW2o7D6Qsudn8M90PraqG38HNwCgz8gy 3FpSUviE/YofOou2rQSUJlA=YQmB -----END PGP SIGNATURE-----
I don''t actually care how many domains a site has, so I just store that info as a text info and no model for domains. However, I found the solution to what I want, very much close (99.99%): 1. still use "SetEnv site_id 10" in Apache Virtual Host 2. then access it as request.env_table[''site_id''] instead of ENV[''site_id''], the later was never set. I''m happy now :-) Kevin On 10/6/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Oct 6, 2005, at 1:45 PM, K C wrote: > > After some reading, I don''t think this can be done by mod_scgi and > > SRR. If I understand right, mod_scgi is client and SRR is server, and > > the client can''t change the server''s ENV. > > > > An alternative is to use mod_rewrite to append the var to the > > request...but that''s less elegant though :-( and maybe unsecure as > > anybody can append a site_id=value to the URL to try to fool the > > server. > > > > Anybody any idea? > > How about putting the Site has_many :domains mapping in the db > instead of your vhost config? > > class Site < ActiveRecord::Base > has_many :domains > end > > class Domain < ActiveRecord::Base > belongs_to :site > end > > class ApplicationController < ActionController::Base > attr_reader :site > before_filter :find_site_by_domain > > private > def find_site_by_domain > domain = Domain.find_by_domain(request.domain) > @site = domain.site unless domain.nil? > end > end > > Best, > jeremy > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.2 (Darwin) > > iD8DBQFDRZALAQHALep9HFYRAhDjAJ472RIwvXWTwrQKCHjLEOPMKjh01gCgq1EJ > g0YBwu5/ndj+CShdai7Ku4M> =1hSu > -----END PGP SIGNATURE----- >