Creating virtual hosts in Apache is very simple actually. I have
already created virtual interface tied to loopback so it will always
go up if I start up my machine. So im going to create hosts file first
to make sure it reads my 2 sites:
root@yuvi:/etc/apache2# more /etc/hosts
127.0.0.1 localhost.localdomain localhost
::1 yuvi localhost6.localdomain6 localhost6
127.0.0.1 www.website1.com
192.168.1.1 www.website2.com
root@yuvi:/etc/apache2# ifconfig lo
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:425 errors:0 dropped:0 overruns:0 frame:0
TX packets:425 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:39387 (39.3 KB) TX bytes:39387 (39.3 KB)
root@yuvi:/etc/apache2# ifconfig lo:0
lo:0 Link encap:Local Loopback
inet addr:192.168.1.1 Mask:255.255.255.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
It looks like there are 2 sites configuration:
root@yuvi:/etc/apache2# ls
apache2.conf conf.d envvars httpd.conf magic mods-available
mods-enabled ports.conf sites-available sites-enabled
root@yuvi:/etc/apache2# ls sites-available/
default default-ssl
root@yuvi:/etc/apache2# ls sites-enabled/
000-default
So now, im going to play around with sites-available first, adding it
in. Virtual Host which listens in 192.168.1.1 is the new one i"ve
added.
root@yuvi:/etc/apache2# more sites-available/default
<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/website1/public_html/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/website1/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/yuvi/website2/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/yuvi/website2/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Then go to sites-enabled, like the first one, the 192 part, is me adding it in.
<VirtualHost 127.0.0.1:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/website1/public_html/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/website1/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</Directory>
</VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/yuvi/website2/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/yuvi/website2/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
That's pretty much it. Very easy, actually we dont have to add
sites-enabled, because in the apache2.conf, it only includes
sites-enabled.
Tidak ada komentar:
Posting Komentar