Setting up a name based Virtual Host in Apache Web Server

December 6, 2012
By

In the article titled, “Setting up DNS server in Ubuntu Linux“, we have setup a name server in an Ubuntu machine. Also we have added the host wptrafficanalyzer.local which points to the machine whose ip address is 192.168.1.3.

In this article we will see, how to set up a name based virtual host using Apache Web Server, so that, the request to the domain wptrafficanalyzer.local in the local area network ( LAN ) will serve a web page.


1. What to do

We will do the following things to setup the site wptrafficanalyzer.local in the LAN:

  • Install apache2 web server in 192.168.1.3 ( Ubuntu 12.04 LTS )
  • Configure apache2 web  server to enable name based virtual hosting
  • Adding the domain wptrafficanalyzer.local to the apache server
  • Adding the site content
  • Restarting the apache server
  • Testing the site in a browser

2. Installing apache2 web server in 192.168.1.13


sudo apt-get install apache2


3. Configuring apache2 web server to enable name based virtual hosting

3.1 Open the file /etc/apache2/apache2.conf and add the given below line just above the line Include sites-enabled/


NameVirtualHost *:80


4. Adding the domain wptrafficanalyzer.local to the apache server

4.1 Create a file namely wptrafficanalyzer.local in the directory /etc/apache2/sites-available and add the given below lines


<VirtualHost *:80>
    ServerName wptrafficanalyzer.local
    DirectoryIndex index.html
    DocumentRoot /var/www/wpta
</VirtualHost>


4.2 Enabling the site wptrafficanalyzer.local in the apache server by issuing the given below command


$sudo a2ensite wptrafficanalyzer.local


5. Adding the site content
As specified in the file /etc/apache2/sites-available/wptrafficanalyzer.local, the document root to our site is /var/www/wpta.

So create an html file namely index.html with the given below code.

<html>
    <body>
        <h1>Welcome to wptrafficanalyzer.local</h1>
    </body>
</html>

6. Restarting apache2 server


$sudo service apache2 restart


7. Testing the site in a browser

Input the address http://wptrafficanalyzer.local in a browser and see the result. We can see a page similar to the page  shown in the given below Figure 1.

Displaying the home page of wptrafficanalyzer.local in a web browser

Figure 1 : Displaying the home page of wptrafficanalyzer.local in a web browser


How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs
store4js.blogspot.com


Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner