How Apache configures multiple Web sites

Source: Internet
Author: User

Turn from: http://www.server110.com/apache/201309/1390.html


Apache's virtual host is a solution that allows you to run more than one Web site on the same machine. There are two kinds of virtual hosts, one is called ip-based (ip-based), the other is named based (name-based). The presence of a virtual host is transparent to the user.

ip-based Virtual Host:
For ip-based virtual hosts, each virtual host must be equipped with a single IP. That means your server must have multiple IP addresses. In this way, we can do an experiment locally to configure.
Configure ip-based Virtual host, there are two ways: first, to start multiple Apache server, each instance using a separate configuration file, in general, on the same machine, set up two sites, the two sites do not want each other to access their own files, use this way, Each Apache instance is started with a separate username, a group, and placed in a different directory, as long as in the Apche configuration file, for the Listen command to configure a different IP;
The second method is to start only a single Apache process, using the VirtualHost instructions for different sites, configure different values, this configuration, we can do a local test, because 127.0.0.* all IP is pointing to the native, so, We can just take two of them out to do experiments, according to the following way to configure Apache, after, in the Hosts file, the domain name binding to the configured IP, you can implement a local operation of a number of WP system configuration:
<virtualhost 127.0.0.1:80>
ServerAdmin yourname@domain.com
DocumentRoot "E:/server110.com/wordpress-latest"
ServerName server110.com
Serveralias www.server110.com
ErrorLog "Logs/wplatest.com-error.log"
Customlog "Logs/server110.com-access.log" combined
</VirtualHost>
<virtualhost 127.0.0.2:80>
ServerAdmin yourname@domain.com
DocumentRoot "e:/server110.com/wordpress-2.9.2"
ServerName server110.com
Serveralias www.server110.com
ErrorLog "Logs/server110.com-error.log"
Customlog "Logs/server110.com-access.log" combined
</VirtualHost>

Name-based virtual host:
Based on the name of the virtual host than ip-based, configuration to be more simple, it relies on the HTTP headers sent by the host field to determine the server in the end to service which virtual host. In general, it is recommended to use this method in comparison. Because of the increasingly scarce IP resources, for the general user, for a server to buy multiple IP is also a high cost.
When configured in this way, the first is to use the namevirtualhost instruction, configure the secondary Apache instance listener IP address and port number, and then use the VirtualHost instructions to configure a different virtual host, the above example, configured in this way, the configuration method is as follows (note, In this way, servername is a required field:
Namevirtualhost 127.0.0.1:80
<virtualhost *:80>
ServerAdmin yourname@domain.com
DocumentRoot "E:/server110.com/wordpress-latest"
ServerName server110.com
Serveralias www.server110.com
ErrorLog "Logs/server110.com-error.log"
Customlog "Logs/server110.com-access.log" combined
</VirtualHost>
<virtualhost *:80>
ServerAdmin yourname@domain.com
DocumentRoot "e:/baidu.com/wordpress-2.9.2"
ServerName baidu.com
Serveralias www.baidu.com
ErrorLog "Logs/baidu.com-error.log"
Customlog "Logs/baidu.com-access.log" combined
</VirtualHost>
This configuration method can also be done locally in a simple experiment.



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.