Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apache2 : Vertial Hosting In 2 Minutes Flat
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
DevX
n00b
n00b


Joined: 08 Apr 2004
Posts: 26

PostPosted: Wed Dec 15, 2004 1:19 am    Post subject: Apache2 : Vertial Hosting In 2 Minutes Flat Reply with quote

A simple script that adds vertial hosts, all you need is apache2.

First make sure you have:
Code:

/etc/apache2/conf/apache2.conf:
Include conf/vhosts/vhosts.conf

uncommented.

here is the script.
Code:

#
# Simple script to create vertial hosts for apache2 with ip aliases.
# Settings are permament.
#
# Parameters required are #1 the ip address or domain name, #2 the vertial host
# number, for example your first virtual host is 0 then comes 1, 2, 3, 4, 5, 6....
#
# DON'T FORGET TO CHECK THE CONFIGURATION FIRST!!
#
# May bee some smart scripter can figure away around the #2 using ifconfig, i cant be
# assed.
#

#
#   C O N F I G U R A T I O N
#
INTERFACE="eth1"
VHOST_CONFIG="/etc/apache2/conf/vhosts/vhosts.conf"
WWW_DIR="/var/www/localhost/htdocs/"

#
#   I P   A L I A S E
#
echo " creating ip aliase for host:"$1" vhost number "$2"."
/sbin/ifconfig $INTERFACE:$2 $1
/sbin/route add -host $1 dev $INTERFACE:$2

echo " adding ip aliase to local.start."
echo "/sbin/ifconfig "$INTERFACE":"$2" "$1 >> /etc/init.d/local.start
echo "/sbin/route add -host "$1" dev "$INTERFACE":"$2 >> /etc/init.d/local.start
#
#   V H O S T   C O N F I G
#
echo " setting up apache2 vhost for host:"$1
echo "<VirtualHost "$1">" >> $VHOST_CONFIG
echo "ServerAdmin admin@address.com" >> $VHOST_CONFIG
echo "DocumentRoot /var/www/localhost/htdocs/"$1"/" >> $VHOST_CONFIG
echo "ServerName "$1 >> $VHOST_CONFIG
echo "ErrorLog /usr/lib/apache2/logs/"$1"_error_log" >> $VHOST_CONFIG
echo "TransferLog /usr/lib/apache2/logs/"$1"_access_log" >> $VHOST_CONFIG
echo "</VirtualHost>" >> $VHOST_CONFIG
echo "" >> $VHOST_CONFIG
echo " "$VHOST_CONFIG" updated."
#
#   H O S T   D I R E C T O R Y   &   H O M E   P A G E
#
echo " creating vhost directory."
mkdir $WWW_DIR""$1
echo " creating index.htm."
echo "<HTML>" >> $WWW_DIR""$1/index.htm
echo "<P> Host : "$1" </P>" >> $WWW_DIR""$1/index.htm
echo "<P> THIS SITE IS UNDER CONSTRUCTION. </P>" >> $WWW_DIR""$1/index.htm
echo "</HTML>" >> $WWW_DIR""$1/index.htm

echo " restarting apache2"
/etc/init.d/apache2 restart

echo " done."


Check the script bits at the top then.

Copy the script text to a file say vhost.sh then chmod 755 vhost.sh and finaly...

Code:

./vhost.sh 192.168.0.5 0
 # for example replace ip.


Hope that made it fast for you.
_________________
Still Dreaming
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum