How Apache configures multiple Web sites

Source: Internet
Author: User
Tags hosting

Apache Virtual Hosting is a solution that allows more than one website to run on the same machine. There are two kinds of virtual hosts, one is called IP-based (ip-based) and the other is name-based (name-based). The existence of a virtual host is transparent to the user.

IP-based virtual hosts:
For IP-based virtual hosts, each virtual host must be equipped with a separate IP. This means that your server must have multiple IP addresses. In this way, we can do a local experiment to configure.
Configure IP-based virtual host, there are two methods: one is to launch 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, the use of this way, Each Apache instance is started with a separate user name, group, and placed in a different directory, this way as long as in the Apche configuration file, for the Listen command configuration of different IP;
The second method is to start a single Apache process, using the virtualhost instruction to configure different values for different sites, this configuration, we can do a local experiment, because all the 127.0.0.* IP is pointing to the machine, so, We can just take two out to do the experiment, configure Apache as follows, then, in the Hosts file, bind the domain name to the configured IP, you can implement a configuration to run multiple WP systems locally:
<virtualhost 127.0.0.1:80>
ServerAdmin [email protected]
documentroot "e:/server110. Com/wordpress-latest "
ServerNameserver110. 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 [email protected]
documentroot "e:/server110. com/wordpress-2.9.2 "
ServerNameserver110. com
Serveralias www.server110. com
errorlog "logs/server110. Com-error.log "
Customlog "logs/server110. Com-access.log "Combined
</VirtualHost>

name-based virtual hosting:
the name-based virtual host is simpler to configure than IP-based, as long as it relies on the host field in the HTTP header information sent by the client to determine which virtual host the server is actually serving. In general, it is recommended to use this method for comparison. Because IP resources are becoming scarce, it is also expensive for average users to purchase multiple IPs for a single server.
when configured in this way, the first is to configure the IP address and port number of the secondary Apache instance listening with the namevirtualhost instruction, and then use the virtualhost instruction to configure the different virtual hosts, the above example, if configured in this way, The configuration method is as follows (note that in this way, servername is a required field):
namevirtualhost 127.0.0.1:80
<virtualhost *:80>
ServerAdmin [email protected]
documentroot "e:/server110. Com/wordpress-latest "
ServerNameserver110. com
Serveralias www.server110. com
errorlog "logs/server110. Com-error.log "
Customlog "logs/server110. Com-access.log "Combined
</VirtualHost>
<virtualhost *:80>
ServerAdmin [email protected]
documentroot "e:/baidu.com/wordpress-2.9.2"
ServerNameBaidu. 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 easily tested locally.

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.