Wednesday, 23 May 2012
 Home arrow Articles arrow linux arrow How to Setup Name-Based Virtual Hosting for Multiple Domains in Apache
   
Main Menu
Home
News
Blog
Links
Search
FAQs
Spider
Articles
@intrenet
Free Softwares
Break for fun
Friends VIdeos
Techno videos
Contact Us
Disclaimer
Guest Book
Speed test
V.E.C. Calculator
IPv4 Subnet Calc
IPv6 Subnet Calc
Byte Converter
Converter
GMT/UTC Time
Bandwidth Calc
Allinone Calc
IANA Port Numbers
Country Call Codes
Pk Postal Codes
Surf Anonumously
Visitors Counter
mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterToday238
mod_vvisit_counterYesterday260
mod_vvisit_counterThis week498
mod_vvisit_counterThis month5047
mod_vvisit_counterAll125723
 
 
 
 


How to Setup Name-Based Virtual Hosting for Multiple Domains in Apache PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Amanatullah khalil   
Saturday, 23 May 2009

How to Setup Name-Based Virtual Hosting for Multiple Domains in Apache

 

Nowadays, domian name is a cheap resource to make your web space cool. After you purchase a domain, most of the domain suppliers allow you to add sub-domains. Then, it is a good idea to provide sub-domains for your friends or your web sites with different styles. In Apache, you can serve multiple domains and sub-domains using one IP address. In this article, I would like to share my experience on setting up virtual host in Apache.

Scenario: We would like to set up name-based virtual hosting. We have two domains (domain1.com, domain2.com) and more subdomains. We want to serve them with one IP address. Our DocumentRoot path is docrootpath (you must replace with your real path).

 

Steps

  • Remove the ServerName definition in the main section (the definitions outside of the VirtualHost section). If you see a definition like Servername www.domain1.com:80 outside of the VirtualHost section, put a ‘#’ character at the head of the line to hide it. We are going to configure all domains in the VirtualHost section. The ServerName definition in the main section may cause some domains not served correctly.
  • Configure VirtualHost. Now we configure one virtual host for every domain/sub-domain that we want to access.
    NameVirtualHost  111.22.33.44:80
    #
    # If you type http://www.domain1.com, the documents under /docrootpath/domain1 will be served
    <VirtualHost 111.22.33.44:80>
    ServerName www.domain1.com
    DocumentRoot /docrootpath/domain1
    </VirtualHost>
    #
    # If you type http://sub.domain1.com, the documents under /docrootpath/domain1/sub will be served
    <VirtualHost 111.22.33.44:80>
    ServerName sub.domain1.com
    DocumentRoot /docrootpath/domain1/sub
    </VirtualHost>
    #
    # If you type http://www.domain2.com, the documents under /docrootpath/domain2 will be served
    <VirtualHost 111.22.33.44:80>
    ServerName www.domain2.com
    DocumentRoot /docrootpath/domain2
    </VirtualHost>
    #
    # If you type http://sub.domain2.com, the documents under /docrootpath/domain2/sub will be served
    <VirtualHost 111.22.33.44:80>
    ServerName sub.domain2.com
    DocumentRoot /docrootpath/domain2/sub
    </VirtualHost>
  • Restart the Apache httpd server by typing $ sudo apachectl graceful

A little more explanation: When Apache gets a request, it searches ServerName in the VirtualHost sections to match the requested domain name. If no VirtualHost matches the requested domain name, the first VirtualHost will be chosen to serve the request.

Source :http://techiecat.catsgarden.net

Thanks to http://techgurulive.com/2009/04/10/how-to-setup-name-based-virtual-hosting-for-multiple-domains-in-apache/
 
< Prev   Next >
 
 
 
csatpk Newsflash
Statistics
OS: Linux h
PHP: 5.2.17
MySQL: 5.1.63-community-log
Time: 05:16
Caching: Disabled
GZIP: Disabled
Members: 3
News: 368
Web Links: 5
Visitors: 266165
Popular