Virtual Host With Apache2 - Debian

Its usually we used http://localhost in our box, how about make a different things with a domain name like http://spydeeyk.com in our box??
http://localhost --> http://spydeeyk.com (in local box)
We can do that.., its called Virtual Host.


1. First add a domain name you want to the host list at /etc/hosts. In this case we add virtual host/domain spydeeyk.com for 127.0.0.1
debian:~# vim /etc/hosts
127.0.0.1 localhost spydeeyk.com
127.0.1.1 debian.eepis-its.edu debian

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
debian:~#
2. Make a file called virtual at /etc/apache2/conf.d
edit /etc/apache2/conf.d/virtual, write NameVirtualHost * , then save!

3. Copy /etc/apache2/site-available/default to make a backup.
debian:~# cp /etc/apache2/sites-available/default /etc/apache2/sites-available/default.backup
4. Edit /etc/apache2/site-available/default.

NameVirtualHost * --> Remove this line
<VirtualHost *>
NameServer your-name-server.com --> Add the virtual host name
ServerAdmin webmaster@localhost

DocumentRoot /var/www/ --> Change to whatever..
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/> --> Change to whatever..
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/ --> Block this
</Directory>
...
...

This my configuration:
<VirtualHost *>
ServerName spydeeyk.com
ServerAdmin webmaster@localhost

DocumentRoot /home/spydeeyk/public_html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/spydeeyk/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# RedirectMatch ^/$ /apache2-default/
</Directory>

...
...
Let's check it at browser..


4 comments:

  1. hahaha,.. hasil jerih payah ngelab pagi-pagi di kampus tertuang semua disini ya,..

    ReplyDelete
  2. wah oprek2 dah jadi hobi mas yak ?!? :)
    salute euy :)
    oya kalo di windows bisa nggak ?! localhostnya di ganti juga ?!

    ReplyDelete
  3. @ afwan auliyar
    he2.. cuma iseng aja koq.. :D
    di windows juga bisa koq.. :)

    ReplyDelete