BUU has asked for the wisdom of the Perl Monks concerning the following question:

Basically I have 50+ domains that I need to host on one box. All the domains are going to be pointed at the exact same website, and the website it self will be extremely basic, one or two pages of static html. My initial thought when I learned this was to just set up a basic vhost using mod-perl, in the form of a text file with all of the domain names listed, seperated by new lines, then something like:
<Perl> $VirtualHost{'myip'}=[]; open F,"domainlist.txt" or die $!; while(<F>) { chomp($_); push @{$VirtualHost{'myip'}}, { ServerName => $_, DocumentRoot => '/home/foo/bar' } } </Perl>
But then it struck me that this might be some what inefficient. Anyone have any better ideas?

Replies are listed 'Best First'.
•Re: VHosting large number of domains(50+), mod-perl
by merlyn (Sage) on Oct 05, 2003 at 00:48 UTC
      Thanks for the links to mod_vhost_alias, I hadn't seen it before. However I still don't see a good way to get a bunch of domains pointed at the same directory except by doing one of two things, one: Just specifying VirtualDocumentRoot as a specific directory, and then all the the vhosts would resolve to one directory, but what about the other virtual hosts? The other is to create 50 symlinks all pointing to one directory. I suppose that last solution is the best one with vhost, but I don't really like it. Dunno, it seems hard to manage.
Re: VHosting large number of domains(50+), mod-perl
by Aristotle (Chancellor) on Oct 04, 2003 at 23:05 UTC

    Why do you have mod_perl in a server that's only going to serve static pages? That's a huge waste of resources.

    Use a very barebones Apache and generate its httpd.conf using Template Toolkit. No Perl per se required even, just a TT2 template and TT2's tpage script.

    Or just switch to thttpd which maps virtual hostnames to directory names, with the explicit intent of letting symlinks handle aliases.

    Makeshifts last the longest.

      The server isn't only going to server static page. It's also going to serve a variety of other websites, many of them dynamic.

      As for Template Toolkit Isn't that a form of embedded perl + content management systems? What does that have to do with generating a httpd.conf?
      As for generating a httpd.conf, I assume you mean using perl to write a dynamic httpd.conf, perhaps reading a textfile containing the domain names and then writing <VirtualHost> sections directly in the .conf? Does this have any advantages over the mod_perl solution? I can't really see any disadvantages, except the outside generation requires another script to be run, with mod_perl you just restart apache.

      Well, I have apache running for my other websites, I would prefer not to have to run two web servers..
        No, TT2 is what its name says: a toolkit to use templates. It has nothing to do with any other part of content management, and while you can embed Perl that's not its purpose. Whether you generate HTML with it or anything else is up to you. merlyn uses it to generate his http.conf(s?) - that's where I first heard of this idea. And that's just one use. If you don't know about it yet, then have a look at it just because. TT2 is always good to have among one's assortment of tools.

        Makeshifts last the longest.

Re: VHosting large number of domains(50+), mod-perl
by cbraga (Pilgrim) on Oct 04, 2003 at 22:21 UTC
    Inneficient how?

    What you have is a little piece which will run each time the server is restarted. It won't take more than a hundreth of a second to run and won't run more than a couple times a day. It does the job.

    Would an improvement of a order of magnitude in run time make any difference?

      Well, To be honest I wasn't really sure exactly how it was working. Mod-perl is voodoo to me =]. But your reassurances are nice.
Re: VHosting large number of domains(50+), mod-perl
by liz (Monsignor) on Oct 05, 2003 at 06:56 UTC
    What's wrong with ServerAlias, possibly combined with a RewriteRule?

    For example:

    <VirtualHost 1.2.3.4> DocumentRoot /path/to/a/single/directory ServerName www.mainserver.name ServerAlias www.foo.com ServerAlias www.bar.com # etc. etc. about 50 times # all ServerAliases could be a on a single line, # but I prefer seperate lines for readability # only do the following if you want only the main URL to appear in the + URL-bar RewriteEngine On RewriteCond %{HTTP_HOST} !^www.mainserver.name$ [ +NC] RewriteRule ^.*$ http://www.mainserver.name/ [ +R,L] # other stuff you need for these domains </VirtualHost>

    Liz

      Ah, liz, I have no idea how I missed ServerAlias in the apache docs, but that looks perfect for my needs.

      It is better to put the alternative hosts in their own <VirtualHost> block if you are going to use mod_rewrite with them. Otherwise, you get the performance hit of mod_rewrite with every hit on the "real" site.

      <VirtualHost 123.123.123.123> ServerName foo.com ServerAlias www.foo.com ... </VirtualHost> <VirtualHost 123.123.123.123> ServerName other.foo.com ServerAlias bar.com ServerAlias www.bar.com ServerAlias quux.com ServerAlias www.quux.com ... RewriteEngine on # RewriteCond not necessary anymore RewriteRule ... </VirtualHost>

      That said, I must say that I hate typing in all those domains and prefer wildcards, when possible :)

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

        Hrm.. virtualhost wild cards? Can you elaborate please?
Re: VHosting large number of domains(50+), mod-perl
by Anonymous Monk on Oct 05, 2003 at 01:20 UTC

    Just curious, why would one wish to point 50+ domains to the same website? Or do you mean to the same server?

      Um, no I meant the same website.