Appache 2.2 Virtual Host Configuration

Source: Internet
Author: User
Tags apache error log

Appache 2.2 Virtual Host Configuration

From: http://hi.baidu.com/wd_828/item/64fbc5a24a6bcf9b14107313 1. Domain name problem

Suppose we have two domain names: www.aaa.com and www.bbb.com

In order to facilitate testing, we can through the system under the Hosts file, set to resolve the two domain name corresponding to the IP, in the XP system disk WINDOWS\SYSTEM32\DRIVERS\ETC, find Hosts file, in which add two

127.0.0.1 www.aaa.com 127.0.0.1 www.bbb.com

That is, the domain name is pointed to the local computer.

For more information on Hosts file see: Hosts.

2. Files that need to be configured

Need to configure two files, that is, httpd.conf and httpd-vhosts.conf httpd.conf in the Apache server folder in the Conf httpd-vhosts.conf in the Conf folder extra inside

To say a few words, httpd.conf is Apache's main configuration file, including some basic Apache settings, and httpd-vhosts.conf is mainly configured to configure the virtual host configuration file, this embodies the Apache configuration file modular thinking, Some of the most commonly used configurations are modular and convenient to configure and modify.

3. Steps

3.1 Modifying httpd.conf files

(1) Remove the front of the #include conf/extra/httpd-vhosts.conf, meaning that httpd.conf file contains httpd-vhosts.conf This configuration file, which is an expression of Apache's configuration modularity, It said so.

(2) Comment out the ServerName *:80, that is, add before #. ServerName need to be configured in the Httpd-vhosts.conf file, each virtual host corresponding to the ServerName are different, ServerName is usually set as a domain name, of course, can also be set to other, * to express all the domain name of the machine.

(3) Comment out the DocumentRoot "C:/webroot", each virtual host documentroot is different, need to configure in httpd-vhosts.conf, so the comments in the main configuration file.

(4) The <directory "C:/webroot" > Label and its internal options are commented out, that is

#<directory "C:/webroot" > # options None # allowoverride None # Order Allow,deny # Allow to all #</directory> ;

Each virtual host can be configured individually for access restrictions, but also in the httpd-vhosts.conf configuration

All of the comments above are httpd.conf default servername, DocumentRoot, and directory properties, because each virtual host can have its own configuration, so these default annotations can be dropped.

3.2 Modifying httpd-vhosts.conf files

Namevirtualhost *:80

<virtualhost *:80> ServerAdmin webmaster@aaa.com documentroot "c:/webroot/aaa.com" ServerName www.aaa.com Serveralias aaa.com *.aaa.com ErrorLog "Logs/dummy-host.aaa.com-error.log" Customlog Dummy-host.aaa.com-access.log "Common <directory" c:/webroot/aaa.com "> Options none allowoverride None order Allow,deny allow from all </Directory> </VirtualHost>

<virtualhost *:80> ServerAdmin webmaster@bbb.com documentroot "c:/webroot/bbb.com" ServerName www.bbb.com Se Rveralias bbb.com *.bbb.com ErrorLog "Logs/dummy-host2.bbb.com-error.log" Customlog Dummy-host2.bbb.com-access.log "Common <directory" c:/webroot/bbb.com "> Options none allowoverride None order Allow,deny Allow from </Directory>

Alias/vpath "C:/webroot/vpath" <directory "C:/webroot/vpath" > Options none allowoverride none order Allow,deny all ow from all </Directory> </VirtualHost>

It is worth noting that the virtualhost is in order, the top virtualhost is our default site domain name. If you do not comment out the documentroot and ServerName in httpd.conf, both configurations of the first virtual host must be the same as in httpd.conf, including the port. Of course I suggest to comment out the label in Httpd.conf.

ServerAdmin website Administrator mailbox, basically can write casually. DocumentRoot the root directory of the virtual host to ensure that the disk address exists, otherwise Apache will not be able to reload the configuration file with an error. ServerName the virtual host domain name. Serveralias Virtual Host domain name alias, * to indicate the wildcard. such as *.aaa.com can represent bbs.aaa.com or news.aaa.com. ErrorLog Virtual Host error log, you can set your own name, generally saved to the Apache home Directory logs folder. Customlog the virtual host access log. Directory to set access restriction properties for the virtual host home directory. Alias sets a virtual path, such as a second virtual host that can access pages in C:/webroot/vpath through Bbb.com/vpath.

3.3 Configuration Complete Save

        Restart the Apache server, it should be OK, if there are errors, you can check the Apache error log, Note that DocumentRoot's path must really exist, otherwise Apache will complain. References:
http://lamp.linux.gov.cn/Apache/ApacheMenu/index.html

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.