Virtual host berdasarkan IP

Contoh membina virtual host berdasarkan IP untuk pelayan web apache pada Debian Lenny

/etc/network/interfaces pelayan web

auto lo eth0 eth0:0
iface lo inet loopback

iface eth0 inet static
address 192.168.56.3
netmask 255.255.255.0
broadcast 192.168.56.255

# eth0:0 akan menjadi interface untuk vhost1
iface eth0:0 inet static
address 192.168.56.4
netmask 255.255.255.0
broadcast 192.168.56.255

Pasang pakej apache2

aptitude install apache2

Cipta dan edit fail 001-vhost1

mkdir /etc/apache2/logs
touch /etc/apache2/sites-enabled/001-vhost1

Kandungan 001-vhost1 seperti berikut

<VirtualHost 192.168.56.4>
	ServerName www.vhost1.debian.int
	ServerAdmin webmaster@vhost1.debian.int
	DocumentRoot /var/www/vhost1
	ErrorLog logs/www.vhost1.debian.int-error_log
	CustomLog logs/www.vhost1.debian.int-access_log combined
	ScriptAlias /cgi-bin/ /var/www/cgi-bin/vhost1
</VirtualHost>

Buat folder /var/www/vhost1
mkdir /var/www/vhost1

Cipta dan edit fail index.html di dalam /var/www/vhost1 dengan kandungan seperti berikut


<html>
<body><h1>Ini adalah laman virtual host</h1></body>
</html>

Mulakan semula servis apache2
/etc/init.d/apache2 restart

Sepatutnya bila anda semak imbas 192.168.56.4 pada pelungsur web, anda akan nampak

Ini adalah laman virtual host

Maklumat lanjut
Linux Administration Handbook muka surat 767
http://httpd.apache.org/docs/1.3/vhosts/ip-based.html

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>