Sunday, October 2, 2011

Creating Virtual Hosts in Apache

I am sure most of what I am writing is available on the Apache Documentation but posting this so that it will be helpful for Users to configure Simple Virtual Hosts easily and faster. 

To start with "What is a VIRTUAL HOST"??
It is a method of Hosting multiple domain names on a server using a Single IP address. This allows sharing of resources of one server such as memory, processor cycles etc which lead to efficient utilization of the resources increasing the efficiency.

Now all of us know Apache is the HTTP Web Server which stores and maintains large number of Websites, It is designed to achieve a very high performance. To configure Virtual Host in Apache is very simple. It involves performing a few steps:


1.Firstly, Install the new Apache Web Server from the http://httpd.apache.org/ site. The downloads for all the OS are available.

2.After installation the Apache will be present in the following directory by default in case of Windows:  "C:\Program Files\Apache Software Foundation\Apache2.X" or "C:\Program Files (x86)\Apache Software Foundation\Apache2.X" in case if 64-bit machines.The httpd.conf file is present under the "conf" folder.
To create Virtual hosts define the following entries in the httpd.conf file which is present under "C:\Program Files\Apache Software Foundation\Apache2.X\conf" directory.

3.Open the file.In the beginning of the file there will be an entry to Listen on a particular port. By default the port is 80.
To create Virtual Hosts which run on port 81 and 82, include the lines after the Listen 80 line ie:            
    Listen 80 
    Listen 81                
    Listen 82
   .  
 
4.Now go to the bottom of the file and search for the entry:
         # Virtual hosts
         #Include conf/extra/httpd-vhosts.conf
       
5.Add the following under the entry:
          NameVirtualHost *:81
          NameVirtualHost *:82


         <VirtualHost *:81>
         DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs1"
         ServerName www.example1.com


         # Other directives here


         </VirtualHost>


         <VirtualHost *:82>
        DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs2"
        ServerName www.example2.org


        # Other directives here


       </VirtualHost>
    Note: The directory htdocs1 and htdocs2 should be created.
 6.Edit the hosts file located under the System32/drivers/etc/ directory. Add the two entries:
           <ip_address of the machine> www.example1.com         
           <ip_address of the machine> www.example2.com

 7.Save the file and close it. restart the Apache Web server either from Services or console.
 Access the link : http://www.example1.com:81/. It should redirect the control to the htdocs1 directory.Place few files in this directory. It must be served.
 Similary, accessing http://www.example2.com:82/ should be redirected to htdocs2 directory. To access the htdocs folder http://localhost:80/ will do.

Thus, We have setup a dedicated Virtual Host setup in Apache. 

53 comments:

  1. Nicely explained. Here you described the well written article from your in-depth knowledge. Truly impressive and nice information

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete
  2. virtual answering service of Marhaba Reception will help you understand the client even when you are not available. Nobody misses an important call using virtual office receptionist. To know more about it contact us marhabareception.com

    ReplyDelete
  3. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.Rprogramming Training in pune

    Rprogramming Training in Bangalore

    Rprogramming Training in btm

    Rprogramming Training in bangalore

    Rprogramming Training in tambaram

    Rprogramming Training in annanagar

    ReplyDelete
  4. Thank you for sharing such valuable information and tips. This can give insights and inspirations for us; very helpful and informative! Would love to see more updates from you in the future.

    Selenium training in chennai
    Selenium training institute in Chennai
    iOS Course Chennai
    Digital Marketing Training in Chennai
    php courses in chennai
    PHP Training in Velahery
    French Classes in Chennai

    ReplyDelete
  5. This is really too useful and have more ideas and keep sharing many techniques. Eagerly waiting for your new blog keep doing more.
    Aws Training in Bangalore
    Aws Course in Bangalore
    Best Aws Training in Bangalore
    hadoop classes in bangalore
    hadoop institute in bangalore

    ReplyDelete
  6. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    Selenium testing training
    Selenium Courses in Chennai
    Selenium training Chennai
    Software Testing Training in Chennai
    Software Testing Courses in Chennai
    Software Training Institutes in Chennai

    ReplyDelete
  7. I'm really glad that I came across your post. I was searching for this information. Thanks for sharing.
    LINUX Training in Chennai | LINUX Course | Best LINUX Training institute in Chennai | LINUX Course in Chennai

    ReplyDelete
  8. I think this is the best article today about the future technology. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic.Artificial Intelligence Training in Bangalore. Keep sharing your information regularly for my future reference.

    ReplyDelete
  9. Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
    SEO company in coimbatore
    SEO company
    web design company in coimbatore

    ReplyDelete
  10. Thanks for sharing this information admin, it helps me to learn new things. Continue sharing more like this.
    Regards,
    Tableau training in Chennai | Tableau Courses Training in Chennai | Tableau training Institute in Chennai

    ReplyDelete
  11. many peoples want to join random whatsapp groups . as per your demand we are ready to serve you whatsapp group links . On this website you can join unlimited groups . click and get unlimited whatsapp group links

    ReplyDelete
  12. Are your preparing for government examination? Effective preparation is important to be successful, make use of our TNPSC Current affairs to prepare for your TNPSC & other government examination.

    ReplyDelete


  13. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
    Data Science Training in Chennai | Data Science Course in Chennai
    Python Course in Chennai | Python Training Course Institutes in Chennai
    RPA Training in Chennai | RPA Training in Chennai
    Digital Marketing Course in Chennai | Best Digital Marketing Training in Chennai

    ReplyDelete
  14. Thanks for sharing valuable information.It will help everyone.keep Post.
    Kerala Lottery guessing

    ReplyDelete
  15. Thank you for this great article i learn a lot from your article keep it up.
    WordPress with LEMP Stack

    ReplyDelete
  16. Alleyaaircool is the one of the best home appliances repair canter in all over Delhi we deals in repairing window ac, Split ac , fridge , microwave, washing machine, water cooler, RO and more other home appliances in cheap rates

    Window AC Repair in vaishali
    Split AC Repair in indirapuram
    Fridge Repair in kaushambi
    Microwave Repair in patparganj
    Washing Machine Repair in vasundhara
    Water Cooler Repair in indirapuram
    RO Service AMC in vasundhara
    Any Cooling System in vaishali
    Window AC Repair in indirapuram

    ReplyDelete
  17. Get the best nursing services baby care services medical equipment services and allso get the physiotherapist at home in Delhi NCR For more information visit our site

    nursing attendant services in Delhi NCR
    medical equipment services in Delhi NCR
    nursing services in Delhi NCR
    physiotherapist at home in Delhi NCR
    baby care services in Delhi NCR

    ReplyDelete
  18. Thank you for excellent article.You made an article that is interesting.
    Tavera car for rent in chennai|Indica car for rent in chennai|innova car for rent in chennai|mini bus for rent in chennai|tempo traveller for rent in chennai
    Keep on the good work and write more article like this...

    Great work !!!!Congratulations for this blog


    ReplyDelete