Build multiple sites using Apache

Source: Internet
Author: User

Apache Virtual Host is a solution that allows running more than one website on the same machine. There are two types of virtual hosts: IP-based and name-based ). The existence of virtual hosts is transparent to users.

IP-based VM:

For IP-based virtual hosts, each virtual host must have a separate IP address. That is to say, your server must have multiple IP addresses. In this way, we can make an experiment locally for configuration.

There are two ways to configure an IP-based Virtual Host: one is to start Multiple apache servo programs and each instance uses a separate configuration file. Generally, on the same machine, set up two websites. The two websites do not want each other to access their own files. In this way, each apache instance is started with a separate user name and group, and put it in different directories. In this way, you only need to configure different ip addresses for the Listen command in the apche configuration file;

The second method is to start a single apache process and use the VirtualHost command to configure different values for different sites. In this way, we can perform a local test, because 127.0.0. * All ip addresses are directed to the local machine. Therefore, we can take two of them and configure apache as follows. Then, in the hosts file, by binding a domain name to the configured ip address, you can run one configuration of multiple wp systems locally:

<VirtualHost 127.0.0.1: 80>
ServerAdmin yourname@domain.com
DocumentRoot "E:/sexywp.com/wordpress-latest"
ServerName wplatest.com
ServerAlias www.wplatest.com
ErrorLog "logs/wplatest.com-error. log"
CustomLog "logs/wplatest.com-access. log" combined
</VirtualHost>

<VirtualHost 127.0.0.2: 80>
ServerAdmin yourname@domain.com
DocumentRoot "E:/sexywp.com/wordpress-2.9.2"
ServerName wpstable.com
ServerAlias www.wpstable.com
ErrorLog "logs/wpstable.com-error. log"
CustomLog "logs/wpstable.com-access. log" combined
</VirtualHost>

Name-based VM:

The name-based VM is simpler than the IP-based VM. It depends on the HOST field in the HTTP header sent by the client to determine which vm The server serves. Generally, this method is recommended for price comparison. Because IP resources are increasingly scarce, it is costly for general users to purchase multiple IP addresses for one server.

When using this configuration method, first use the NameVirtualHost command to configure the IP address and port number of the apache instance listener, and then use the VirtualHost command to configure different virtual hosts, the configuration method is as follows (note that in this method, ServerName is a required field ):

NameVirtualHost 127.0.0.1: 80

<VirtualHost *: 80>
ServerAdmin yourname@domain.com
DocumentRoot "E:/sexywp.com/wordpress-latest"
ServerName wplatest.com
ServerAlias www.wplatest.com
ErrorLog "logs/wplatest.com-error. log"
CustomLog "logs/wplatest.com-access. log" combined
</VirtualHost>

<VirtualHost *: 80>
ServerAdmin yourname@domain.com
DocumentRoot "E:/sexywp.com/wordpress-2.9.2"
ServerName wpstable.com
ServerAlias www.wpstable.com
ErrorLog "logs/wpstable.com-error. log"
CustomLog "logs/wpstable.com-access. log" combined
</VirtualHost>

This configuration method can also be used locally for simple experiments.

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.