User Tools

Site Tools


bdnog5:track2agenda:web-service-lab
//[lab source : NSRC]//

1 Apache and Virtual Hosts Exercises

1.1 Install Apache version 2

Apache is already installed on your machines, but if it was not you would simply do:

apt-get install apache2

As the root user. Once Apache is installed it is up and running. The startup defintion for Apache is /etc/init.d/apache2. You can stop, start, restart, reload Apache by doing:

# service apache2 stop
# service apache2 start
# service apache2 restart
# service apache2 reload

1.2 Configure Virtual Hosts in Apache 2

1.2.1 Directory Structure There are several ways to approach virtual hosting. The first thing you must determine is your directory structure where each web site will reside. For our purposes we will use the standard Linux convention of:

/var/www/VirtualHostName1
/var/www/VirtualHostName2
/var/www/etc…

1.2.2 Multiple Names All of your PCs have DNS entries for their assigned IP addresses on the Authoritative nameserver for the zone apnictraining.net – that is on 192.168.30.249 & 192.168.30.250. Thus, you can use:

groupX.apnictraining.net -> 192.168.30.X

to access your machines. We will take advantage of this for the exercise.

1.2.3 Web Directories Let's create the web directories that we’ll need:

# cd /var/www/
# mkdir groupX.apnictraining.net

Be sure you replace “X” with the number of your PC.

1.2.4 Index Files Now let's create a HTML file to our groupX.apnictraining.net directory:

# vi groupX.apnictraining.net/index.html

Put the following html code:

<html>
<title>Apache2 Ubuntu Default Page: It works</title>
<body>
<h1>bdNOG5 Linux Workshop<h1>
<h2>groupX.apnictraining.net Virtual Host<h2>
</body>
</html>

Close and save the file.

1.2.5 Apache Configuration Files Now we need to adjust the Apache configuration files for our two new sites. We will treat the groupX.apnictraining.net site as our default site – that is, where people arrive if, for some reason, the come to our box without specifying a host name (for instance, if they use an IP address instead):

# cd /etc/apache2/sites-available
# vi 000-default.conf

In the file default we will change the “DocumentRoot” setting to point to the directory for groupX.apnictraining.net. Look for this line:

DocumentRoot /var/www/html

Change this line to read:

DocumentRoot /var/www/groupX.apnictraining.net

Save the file and exit. Now let’s restart Apache and see if the server is still working:

 # service apache2 restart 

In a web browser (on your machine) open the URLhttp://groupX.apnictraining.net/” and you should see:

bdNOG5 Linux Workshop
groupX.apnictraining.net Virtual Host

1.3 Log Files Apache logs are under /var/log/apache2 folder. Go through the access.log & error.log for better understanding.

bdnog5/track2agenda/web-service-lab.txt · Last modified: 2016/04/03 17:01 by Fakrul Alam