Date: Fri, 12 Jul 2002 09:18:47 -0500 From: "Mark Johnston" <mjohnston@skyweb.ca> To: "'Odhiambo Washington'" <wash@wananchi.com> Cc: <freebsd-isp@freebsd.org> Subject: Re: Scripts to Manage Virtual Hosts Message-ID: <001b01c229af$0a181040$3e0fa8c0@skycable.int> In-Reply-To: <20020712135040.GM10377@ns2.wananchi.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi Wash,
As opposed to manipulating httpd.conf, I've used Apache's Include
<directory> directive to make the vhost configuration files easier to
manage. I include the NameVirtualHost directives in httpd.conf, then
follow them with
Include /home/www/vhosts
Each file in /home/www/vhosts represents a domain and contains one
<VirtualHost> block. I don't do a lot of customization to them, but
this snippet builds a new one:
sub addvhost {
my $domain = shift;
print "Setting up apache: ";
if (-f "/home/www/vhosts/$domain") {
print "Rewriting vhost config file... ";
} else {
print "Creating vhost config file... ";
};
# If others can write to /home/www/vhosts/$domain, this will
give you a race condition
open F, ">/home/www/vhosts/$domain" or do {
print "$!\n";
return;
};
print F <<EOF;
<VirtualHost my.ip.addr>
ServerName $domain
ServerAlias www.$domain
ServerAdmin webmaster\@$domain
DocumentRoot /home/www/$domain
ErrorLog /home/www/$domain/logs/error_log
CustomLog /home/www/$domain/logs/access_log combined
Alias /icons/ "/home/apache/icons/"
<Directory /home/www/$domain>
Options Indexes
AllowOverride None
</Directory>
<Directory /home/www/$domain/logs>
Options Indexes
AllowOverride Limit AuthConfig
</Directory>
</VirtualHost>
EOF
close F;
print "ok.\n";
# Another one here :)
# Adjust UIDs appropriately
chown 511, 511, "/home/www/vhosts/$domain" or die "$!";
print "/home/apache/bin/apachectl graceful: ";
print `/home/apache/bin/apachectl graceful`;
print "\n";
};
(Yes, /home/apache and /home/www make for a lousy directory layout -
this is actually on a cobalt raq running Linux, but the same principles
apply. ;)
This is handy for a few reasons - a couple are no blocking on httpd.conf
and no chance of munging it if your script runs amok.
Hope this helps,
Mark Johnston
Network Systems Analyst, SkyWeb
mjohnston@skyweb.ca
(204) 925-9125 / 1-888-244-5544
-----Original Message-----
From: owner-freebsd-isp@FreeBSD.ORG
[mailto:owner-freebsd-isp@FreeBSD.ORG] On Behalf Of Odhiambo Washington
Sent: Friday, July 12, 2002 8:51 AM
To: FBSD-ISP
Subject: Scripts to Manage Virtual Hosts
[ I sent this to -questions but got no help ;) ]
Hello Users,
I believe someone already had written a script that can be used to
manipulate
httpd.conf to add/remove virtual host entries.
I sincerely believe that this is somewhere so I don't have to start
agonizing
about re-inventing the wheel.
Could someone kindly point me to where one is located, better even share
with me
what they have ;-)
-Wash
--
Odhiambo Washington <wash@wananchi.com> "The box said 'Requires
Wananchi Online Ltd. www.wananchi.com Windows 95, NT, or better,'
Tel: 254 2 313985-9 Fax: 254 2 313922 so I installed FreeBSD."
GSM: 254 72 743 223 GSM: 254 733 744 121 This sig is McQ! :-)
The light at the end of the tunnel is the headlight of an approaching
train.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-isp" in the body of the message
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-isp" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001b01c229af$0a181040$3e0fa8c0>
