Quantcast
Viewing all articles
Browse latest Browse all 2

Ubuntu, Apache: Virtual Hosting

Virtual Hosting in Ubuntu Hardy Heron: Case Example

Consider the case of two domain names mysite1 and site2 to be served on IP Address 192.168.1.100 (port 80)

Before proceeding let us look at how resolv.conf and hosts file are set up …

$ cat /etc/resolv.conf
search kurinchilion.com
nameserver 192.168.1.100

$ cat /etc/hosts
127.0.0.1 localhost
192.168.1.100 myserver.kurinchilion.com myserver

# 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


We can organize the name server information, directory to serve under each circumstance, folder permission in different ways

i) organize all name server information under /etc/apache2/conf.d/vhosts.conf

NameVirtualHost 192.168.1.100
<VirtualHost 192.168.1.100:80>
ServerName mysite1
DocumentRoot /var/www/mysite1
<Directory /var/www/mysite1>
Options -Indexes FollowSymLinks
AllowOverride All
< </VirtualHost>

<VirtualHost 192.168.1.100:80>
ServerName mysite2
DocumentRoot /home/mysite2
</VirtualHost>

After creating the above file, issue the following commands

$ sudo /etc/init.d/apache2 restart

$ sudo /etc/init.d/apache2 force-reload

ii) have a modular approach to site organization and list separate files based on domain name under /etc/apache2/sites-enabled

File: mysite1
<VirtualHost 192.168.1.100:80>
ServerName mysite1
DocumentRoot /var/www/mysite1

Options FollowSymLinks
AllowOverride All

</VirtualHost>

File: mysite2
<VirtualHost 192.168.1.100:80>
ServerName mysite2
DocumentRoot /home/mysite2
</VirtualHost>

After creating the above files, issue the following commands

$ a2ensite mysite1

$ a2ensite mysite2

(If you want to disable the site configuration, then issue a2dissite sitename)

$ sudo ln -s /etc/apache2/sites-available/mysite1 /etc/apache2/sites-enabled/mysite1

$ sudo ln -s /etc/apache2/sites-available/mysite2 /etc/apache2/sites-enabled/mysite2

$ sudo /etc/init.d/apache2 restart

$ sudo /etc/init.d/apache2 force-reload

iii) Organize the same information stated in step (i) but under /etc/apache2/sites-available/default (This already has a symbolic link to /etc/apache2/sites-enabled/000-default)


Viewing all articles
Browse latest Browse all 2

Trending Articles