Apache's virtual hosting service means that a machine is virtualized into multiple Web servers. Specifically, we can use the virtual hosting service to assign two domain names to the same server, and visitors can access them as long as they enter the domain name. For example, in this machine, we configure www.aaa.com and www.bbb.com. Domain-based virtual hosting services do not require multiple IP addresses, are simple to configure, and require no special hardware support. The following configuration is a domain-based virtual host configuration under Windows, and the Apache version is httpd-2.2.22. Set up two virtual hosts on this machine, assuming that the site domain name is www.51venus.com and 51venus.com, respectively.
httpd.conf file Configuration
First, locate the following configuration in the file
# Virtual Hosts
#Include conf/extra/httpd-vhosts.conf
Get rid of the # before include, this is the comment symbol, into the following:
# Virtual Hosts
Include conf/extra/httpd-vhosts.conf
Then find the following three strings at the beginning of the statement, plus # comment out, such as:
#ServerAdmin
#ServerName
#DocumentRoot
Then, modify the conf/extra/httpd-vhosts.conf configuration file,
And then how to modify it?
First modified: VirtualHost
1 namevirtualhost *:802// change to 3 namevirtualhost 127.0.0.1
Then modify: VirtualHost and directory, as I modified this example:
1<virtualhost 127.0.0.1>2ServerAdmin [email protected]com3DocumentRoot "D:/xampp/htdocs/www"//to correspond to the directory name below and set directory permissions4ServerName Www.51venus.com5Serveralias Www.51venus.com6Errorlog "Logs/www.51venus.com-error.log"7Customlog "Logs/www.51venus.com-access.log"Common8</VirtualHost>9 Ten<virtualhost 127.0.0.1> OneServerAdmin [email protected]com ADocumentRoot "D:/xampp/htdocs/venus" -Servername51venus.com -Serveralias 51venus.com theErrorlog "Logs/51venus.com-error.log" -Customlog "Logs/51venus.com-access.log"Common -</VirtualHost> - +<directory "D:/xampp/htdocs/www" > - Options Indexes followsymlinks multiviews + allowoverride All AOrder Allow,Deny at allow from all -</Directory> - -<directory "D:/xampp/htdocs/venus" > - Options Indexes followsymlinks multiviews - allowoverride All inOrder Allow,Deny - allow from all to</Directory>
I use PHP syntax style here, the actual application to be modified.
Finally, modify the Hosts file (c:\windows\system32\drivers\etc\hosts) to open with a text file to
Add the following code below the file:
127.0.0.1 www.51venus.com 51venus.com
Restart the server, access the bar!
Apache configuration virtual host based on domain name