Apache supports configuring multiple virtual hosts on one server. One IP address corresponds to N domain names, and one domain name corresponds to n different IP addresses.
The following describes how to configure a virtual host on Apache.
1. First, find the Apache configuration file:
CD/usr/local/apache2/CONF/
Ii. edit the file:
Sudo Vim httpd. conf
Because the port number of the configured VM is 8080, add a line under listen 80
LIsten 8080
3. Follow the prompts in httpd. conf:
Configure the VM in the httpd-vhosts.conf under the extra directory
Sudo Vim extra/httpd-vhosts.conf
A) First add a row under namevirtualhost *: 80.
Namevirtualhost*: 8080
B) Add the following content at the bottom of the file:
<Virtualhost *: 8080>
DocumentRoot "/home/daveyhuang/apache_test/htdocs /"
Servername daveyhuang.com
ScriptAlias/cgi-bin/"/home/daveyhuang/apache_test/cgi-bin /"
<Directory"/Home/daveyhuang/apache_test/htdocs">
AllowOverride none
Options none
Order allow, deny
Allow from all
</Directory>
<Directory"/Home/daveyhuang/apache_test/cgi-bin/">
AllowOverride none
Options none
Order allow, deny
Allow from all
</Directory>
</Virtualhost>
Set the default document path to/home/daveyhuang/apache_test/htdocs/
The domain name is
At the same time, the access to cgi-bin on port 8080 is mapped to access to files in/home/daveyhuang/apache_test/cgi-bin.
4. Restart the apache service process
Sudo/usr/local/apache2/bin/apachectl restart
This completes the configuration.
V. Running
Modify the host file in c: \ windows \ system32 \ drivers \ etc. When the browser parses the domain name, it first searches for the IP address corresponding to the domain name in the host file. If it is not found, then go to the DNS for resolution. To make daveyhuang.com correspond to the virtual host I configured, you also need to modify the host file,
Add the following sentence to the host file:
172.25.40.134 daveyhuang.com
In this way, input daveyhuang.com: 8080 in the browser to connect to the corresponding index.html file.