Adding virtual hosts dynamically via mod_perl
I am trying to configure virtual hosts dynamically in mod_perl2. I have a startup file which sets up an 'application' based on my own framework. Part of that inflation creates a number of virtual hosts. I have been trying the following: - In httpd.conf: PerlConfigRequire /path/startup.pl - In startup.pl: my $config = < VHOST Apache2::Server->server->add_config([split /\n/ $config]); - When I tried with PerlRequire or PerlPostConfigRequire, adding the virtual host would give me a segfault. With PerlConfigRequire, it runs fine, but if I do: @vhosts = Apache2::Directive::conftree->lookup("VirtualHost") it doesn't find any virtual hosts. I want to keep the line in httpd.conf as simple as possible. How should I go about doing this? I could use PerlSections, but how? my $config = do 'startup.pl'; #parse config into @vhosts foreach my $vhost (@vhosts) { $VirtualHost{$vhost}=>$config->{$vhost} } Or should I use something like: Or: PerlOpenLogsHandler startup.pl Help appreciated Clinton Gormley [EMAIL PROTECTED] www.TravelJury.com - For travellers, By travellers
Dynamic Proxy Setup???
Hi, I would like to set up dynamic proxy server names in httpd.conf in an Apache/2.2.2 (Unix) mod_apreq2-20051231/2.5.7 mod_perl/2.0.2 Perl/v5.8.8 on Red Hat 2.6.9-34.0.2.ELsmp #1 SMP environment. By this I mean, I have front end servers: F1 and F2, and middle-tier servers M1 and M2. I would like F1 to proxy to M1 and F2 to proxy to M2. I would like to have a small piece of code do this, rather than having unique httpd.conf files for each F# server. This may not be a pure load balanced solution like a load balancer solution, but would like to be able to do this in code/setup for now. NOT: Don't want to do this on F1, httpd.conf: ProxyPass /users/ http://M1/users and NOT: Don't want to do this on F2, httpd.conf: ProxyPass /users/ http://M2/users Want THIS: Want Something like this that would be in httpd.conf in both F1 and F2 ProxyPass /users/ http://$server/users Sorry for the newbie type question. Not sure where to look. Didn't see anything in any of the mod-perl books, nor anything online in google searches, unless I missed something. Thanks as always, Tom
Dynamic Proxy Setup, resend, no styles
Hi, I would like to set up dynamic proxy server names in httpd.conf in an Apache/2.2.2 (Unix) mod_apreq2-20051231/2.5.7 mod_perl/2.0.2 Perl/v5.8.8 on Red Hat 2.6.9-34.0.2.ELsmp #1 SMP environment. By this I mean, I have front end servers: F1 and F2, and middle-tier servers M1 and M2. I would like F1 to proxy to M1 and F2 to proxy to M2. I would like to have a small piece of code do this, rather than having unique httpd.conf files for each F# server. This may not be a pure load balanced solution like a load balancer solution, but would like to be able to do this in code/setup for now. NOT: Don't want to do this on F1, httpd.conf: ProxyPass /users/ http://M1/users and NOT: Don't want to do this on F2, httpd.conf: ProxyPass /users/ http://M2/users Want THIS: Want Something like this that would be in httpd.conf in both F1 and F2 ProxyPass /users/ http://$server/users Sorry for the newbie type question. Not sure where to look. Didn't see anything in any of the mod-perl books, nor anything online in google searches, unless I missed something. Thanks as always, Tom
Re: Adding virtual hosts dynamically via mod_perl
On Mon, 2006-08-14 at 11:08 +0200, Clinton Gormley wrote: > I am trying to configure virtual hosts dynamically in mod_perl2. I figured out what I was doing wrong, so I thought I'd document it, because it took me so long to figure out. According to http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost , "The NameVirtualHost directive is a required directive if you want to configure name-based virtual hosts." I am specifying IP-based virtual hosts and so thought that a NameVirtualHost directive was not required. But it didn't work. When I added the NameVirtualHost directive, it all worked swimmingly. So, to dynamically configure virtual hosts, you can do as follows: In httpd.conf: -- PerlConfigRequire "conf/startup.pl" -- In conf/startup.pl: -- use Apache2::ServerUtil(); my $config = ''; foreach my $site (@sites) { $config.= = <{ip}:80 {ip}:80> ServerName $site->{name} # Other config details CONFIG my $server = Apache2::ServerUtil->server; $server->add_config([split /\n/, config]); -- hope this saves somebody else some pain clint
Re: Dynamic Proxy Setup, resend, no styles
On Mon, 2006-08-14 at 11:44 -0400, Tom Weber wrote: > Hi, > > I would like to set up dynamic proxy server names in httpd.conf in an > Apache/2.2.2 (Unix) mod_apreq2-20051231/2.5.7 mod_perl/2.0.2 > Perl/v5.8.8 on Red Hat 2.6.9-34.0.2.ELsmp #1 SMP environment. Hi Tom having just spent all day looking at dynamic configuration, I know exactly where to look. http://perl.apache.org/docs/2.0/api/Apache2/PerlSections.html and http://perl.apache.org/docs/2.0/api/Apache2/ServerUtil.html#C_add_config_ You could do this as follows: (untested) my $hostname = `hostname`; my %map = ( F1 => 'M1', F2 => 'M2' ); push @ProxyPass,"/users/","http://$map{$hostname}/users";; or, in a startup file: $s = Apache2::ServerUtil->server; $server->add_config("ProxyPass /users/ http://$map{$hostname}/users";); > clint Clinton Gormley [EMAIL PROTECTED] www.TravelJury.com - For travellers, By travellers
Re: Dynamic Proxy Setup, resend, no styles
On Mon, 2006-08-14 at 11:44 -0400, Tom Weber wrote: > By this I mean, I have front end servers: F1 and F2, and middle-tier > servers M1 and M2. I would like F1 to proxy to M1 and F2 to proxy to > M2. I would like to have a small piece of code do this, rather than > having unique httpd.conf files for each F# server. If you're using virtual hosts for these, mod_proxy can just pass the Host header and you send all the traffic to the same mod_perl server and intercept it with VirtualHost sections back there. Otherwise, there are many ways to do templated httpd.conf files. You can use mod_macro or generate conf files with Template Toolkit or a dozen other things. - Perrin
Re: Dynamic Proxy Setup, resend, no styles
Problem solved. I used Clinton's suggestion to put the sections in httpd.conf with just one modifcation: The push @ProxyPass should read: push @ProxyPass, "/users/ http://$server/users";; not: push @ProxyPass, "/users/ ", "http://$server/users";; Being new to dynamic configuration through mod_perl, I can only say that this is AWESOME stuff Lots of synapses now going through my brain. Thanks all, Tom At 11:58 AM 8/14/2006, Clinton Gormley wrote: On Mon, 2006-08-14 at 11:44 -0400, Tom Weber wrote: > Hi, > > I would like to set up dynamic proxy server names in httpd.conf in an > Apache/2.2.2 (Unix) mod_apreq2-20051231/2.5.7 mod_perl/2.0.2 > Perl/v5.8.8 on Red Hat 2.6.9-34.0.2.ELsmp #1 SMP environment. Hi Tom having just spent all day looking at dynamic configuration, I know exactly where to look. http://perl.apache.org/docs/2.0/api/Apache2/PerlSections.html and http://perl.apache.org/docs/2.0/api/Apache2/ServerUtil.html#C_add_config_ You could do this as follows: (untested) my $hostname = `hostname`; my %map = ( F1 => 'M1', F2 => 'M2' ); push @ProxyPass,"/users/","http://$map{$hostname}/users";; or, in a startup file: $s = Apache2::ServerUtil->server; $server->add_config("ProxyPass /users/ http://$map{$hostname}/users";); > clint Clinton Gormley [EMAIL PROTECTED] www.TravelJury.com - For travellers, By travellers
keep alive under mp -- single and multi server strategies
my dev boxes are this: mac osx 10.4 mp2 ports 8080-8090 serves static and dynamic content my prod boxes are: freebsd 6 lighttpd ( probably moving to nginx , as lighty has a gigantic memory leak under heavy proxy use) port 80 for static content and reverse proxy / load balancing mp2 ports 8000 - 9000 serves dynamic content my local box has been sluggish lately. i think it has to do with Keep Alive and a recent Safari update- mp2 tosses all the content in a split second, but the connection hangs and the page doesn't render because the images connection is complete or something, until i reach apache's keepalive timeout shutting that off seemed to have fixed everything. since its a dev box, i'm not worried. that brings me to the keepalive on the server regarding mp2 serving to a reverse proxy. the only info i could find about it was Stas asking for recommendations in 1999. under my naive understanding, KeepAlive should be off in a multi- server setup, as the only item in the connection request should be the single dynamic content page (as the images and css/js files are handled by the proxy). or , am i way off, and the connection is good for multiple requests , and keepalive on would be a bonus?
Re: keep alive under mp -- single and multi server strategies
On Mon, 2006-08-14 at 14:30 -0400, Jonathan Vanasco wrote: > under my naive understanding, KeepAlive should be off in a multi- > server setup, as the only item in the connection request should be > the single dynamic content page (as the images and css/js files are > handled by the proxy). > > or , am i way off, and the connection is good for multiple requests , > and keepalive on would be a bonus? That is totally dependent on what you use for a proxy server. If it shares the open connections between processes, then it might be ok. If it doesn't, you have to turn it off or you'll go over MaxClients, since your proxy would normally be configured to handle at least 10 times as many connections as your application server. - Perrin
debugging tip
i've been going crazy trying to abstract my shared libraries into something where the debug code is manageable and reusable without hacking at the library. my problem was that I made too much use of how perl optimizes away debug code if you use constants i had tons of DEBUG && print STDERR 'info' i tried doing some stuff like i saw in other packages like this our $Debug=0; and then flipping it in the code that uses it. that doesn't allow for perl to optimize stuff away. entering captain obvious mode, i realized use constant DEBUG_CONNECT= $ENV{'P2XLP_DEBUG_CONNECT'} i've now seen a 70% reduction in memory on my workhorse libraries (forms, databse, etc ), which is huge. going from 800k compiled to 140k is a giant memory saver. its not as extensible as some of the other debug options, where you get to change stuff on live code. but i realized that for mod_perl stuff- restarting on a shared environment with a new env is a hassle worth the performance tradeoff. just a tip to anyone else out there who didn't realize this.