Monday, May 19, 2014

How to add two or more than two virtual host in apache web server

We have already installed apache web server. By default it will have only one host machine will have only one host.

By default the directory for apache web server is /var/www directry you can change it by editing "/etc/apache2/sites-available/default" file    



We will see how to make name based and ip based virtual hosting in apache web server.


first you need to install apache web server , open terminal type

"sudo apt-get install apache2"

after installation, open firefox web browser type "127.0.01" or "localhost"

you will see your index page of apache web server.

Now we need another two host called "uman.com" and "anuj.borah.com"

Lets see how i will do it .


The root of document for uman.com will be /home/user/Pictures/uman.com

and root of document for anuj.borah.com will be /home/user/Pictures/anuj.borah.com

here in my case user=u-man


open terminal type

sudo mkdir -p /home/u-man/Pictures/uman.com/

gedit   /home/u-man/Pictures/uman.com/index.html

and past the following


<html>
  <head>
    <title>Welcome to uman.com!</title>
  </head>
  <body>
    <h1>Success!  The uman.com virtual host is working!</h1>
  </body>
</html>
 

save it.

again type 

sudo mkdir -p /home/u-man/Pictures/anuj.borah.com/ 

sudo gedit  /home/u-man/Pictures/anuj.borah.com/index.html


<html>
  <head>
    <title>Welcome to anuj.borah.com!</title>
  </head>
  <body>
    <h1>Success!  The anuj.borah.com virtual host is working!</h1>
  </body>
</html>

save it

now

type it  cd /etc/apache2/sites/avai*

and then sudo gedit uman.com.conf

just past past the following


<VirtualHost uman.com>
ServerAdmin webmaster@localhost
ServerAlias www.uman.com
DocumentRoot /home/u-man/Pictures/uman.com/
#if using awstats
ScriptAlias /awstats/ /usr/lib/cgi-bin/
#we want specific log file for this server
CustomLog /var/log/apache2/example.com-access.log combined
</VirtualHost>


again type sudo gedit anuj.borah.com.conf

and past the following

<VirtualHost anuj.borah.com>
ServerAdmin webmaster@localhost
ServerAlias www.anuj.borah.com
DocumentRoot /home/u-man/Pictures/anuj.borah.com/
#if using awstats
ScriptAlias /awstats/ /usr/lib/cgi-bin/
#we want specific log file for this server
CustomLog /var/log/apache2/example.com-access.log combined
</VirtualHost>


now type  cd ..

cd sites-ena*


sudo ln /etc/apache2/sites-available/uman.com.conf uman.com.conf

sudo ln /etc/apache2/sites-available/anuj.borah.com.conf anuj.borah.com.conf


now type sudo gedit /etc/hosts

copy and past the following

127.0.0.1    localhost
127.0.0.2    uman.com
127.0.0.3    anuj.borah.com


now type sudo service apache2 restart

type uman.com  or anuj.borah.com  in your browser


bellow is the screen -shoot











No comments:

Post a Comment