Home > ICT4TN003-12 - Linux server, Linux, Xubuntu > Linux Server – Task 5: Apache Name-Based Virtual Hosting

Linux Server – Task 5: Apache Name-Based Virtual Hosting

Course
Linux palvelimena [Linux server] by Tero Karvinen at Haaga-Helia University of Applied Sciences

Task
Get name-based virtual hosting working with Apache. Try a virtual private server (VPS) – get it from Amazon, Linode, DigitalOcean, or another similar internet hosting service.

Testing environment
OS: Xubuntu Linux 13.10 “Saucy Salamander” 32-bit (persistent live USB drive)
System: HP EliteBook 2570p Notebook PC

Apache name-based virtual hosting test
I already had Apache (and LAMP) already installed, so I skipped that part this time (instructions on how to install LAMP (in Finnish)).

I had enabled and tested creating and navigating personal web pages with LAMP before (in English) as well, so I merely checked that they were still working by typing in localhost/~xubuntu/index.html in Firefox. Success.

I then created a folder named jannevaris.com in my public_html folder in my home directory, and moved the aforementioned index.html file in it with $ mv index.html jannevaris.com. I navigated to /etc/apache2/sites-available by typing $ cd /etc/apache2/sites-available in the terminal, and created a new config file there with $ sudoedit jannevaris.conf. I added the following lines to the file and saved the changes:

<VirtualHost *:80>
    ServerName www.jannevaris.com
    ServerAlias jannevaris.com
    DocumentRoot /home/xubuntu/public_html/jannevaris.com
</VirtualHost>

After this I enabled the site by entering $ sudo a2ensite jannevaris.conf, and restarted the Apache daemon with $ sudo service apache2 reload. Next I navigated to /etc via $ cd /etc, and edited the hosts file with $ sudoedit hosts. I added my computer’s ip address alongside the desired virtual hosting addresses defined earlier:

127.0.0.1 localhost
127.0.1.1 xubuntu
my-ip www.jannevaris.com
my-ip jannevaris.com

# 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

After this I tested the changes by entering jannevaris.com in Firefox, and the previously mentioned index.html successfully loaded.

References
VirtualHost Examples (http://httpd.apache.org/docs/2.2/vhosts/examples.html)
Karvinen, Tero: Lessons 2014-2-24, Linux palvelimena [Linux server] (http://terokarvinen.com/2013/aikataulu-%E2%80%93-linux-palvelimena-ict4tn003-11-ja-12-kevaalla-2014)

About
This document can be copied and edited according to the GNU General Public License (version 3 or newer). http://www.gnu.org/licenses/gpl.html
Based on a course by Tero Karvinen, http://www.iki.fi/karvinen

Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: