Run multiple domain name-based web sites on one IP Address

Source: Internet
Author: User

Your server has only one IP address, and many domain names (cnames) in DNS are mapped to this machine. You want to runwww.example.comAndwww.example.orgTwo sites.

Note:

Creating a virtual host in your Apache server configuration does not automatically update the host name in your DNS. YouRequiredAdd your own domain name in DNS to point to your IP address. Otherwise, you cannot view your website. You canhostsAdd this entry to the file for testing, but this method only applieshostsFile machines.

Server Configuration

# Ensure Apache listens to port 80
Listen 80

# Listen on all IP addresses for a VM
Namevirtualhost *: 80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com

# You can add other commands here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# You can add other commands here

</VirtualHost>

Because the asterisk matches all IP addresses, the master server does not receive any requests. Becausewww.example.comIt appears in the configuration file first, so it has the highest priority, which can be consideredDefaultOrMasterServer. This means that if a request cannot be associated withServerNameThe command matches<VirtualHost>Segment servo.

Note:

If you want to, you can replace it with a fixed IP address"*". In this case,VirtualHostParametersRequiredAndNameVirtualHostParameters are consistent:

NameVirtualHost 172.20.30.40

<Virtualhost 172.20.30.40>
# Others...

However, when your IP address cannot be determined, use"*"It is very convenient. For example, when your ISP configures Dynamic IP addresses for you and you use a dynamic domain name resolution system. Because"*"Matches any IP address. In this case, no additional configuration is required regardless of the IP address.

The above configuration will be used when you use a domain name-based virtual host in most cases. In fact, this configuration will not satisfy you only in one case: You want to provide different content for different IP addresses or ports.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.