1. Find the httpd. conf file under the \ conf directory of Apache, open it, and find the following two lines:
# Virtual hosts#Include conf/extra/httpd-vhosts.conf
Change it to the following:
# Virtual hostsInclude conf/extra/httpd-vhosts.conf
This means to enable the virtual host's settings file httpd-vhosts.conf, the virtual host settings are all under this file
You do not need to change httpd. conf. This is clear.
2. Find the httpd-vhost.conf file under the \ conf \ extra directory of Apache.
When you open it, it contains the following content:
-The VM configuration starts.
<VirtualHost *:80>ServerAdmin webmaster@dummy-host.localhostDocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.localhost”ServerName dummy-host.localhostServerAlias www.dummy-host.localhostErrorLog “logs/dummy-host.localhost-error.log”CustomLog “logs/dummy-host.localhost-access.log” common</VirtualHost>
Copy the above lines, the key is:
DocumentRoot ""-the virtual host directory, that is, the root directory corresponding to the domain name
Servername dummy-host.localhost-the domain name you want.
Add the following content before each virtual host configuration starts:
<Directory "C: \ test">
Options indexes followsymlinks between des execcgi
AllowOverride all
Order allow, deny
Allow from all
</Directory>
Where:
<Directory "C: \ test">-this is the authorized directory of your VM.
Generally
DocumentRoot ""-the virtual host directory, that is, the root directory corresponding to the domain name
Same.
Allow from all-this sentence is important. As long as allow is used by others to access the directory defined above,
Otherwise, the error 503 is displayed during IE or Firefox access, that is, access is prohibited.
If you don't want to join in the httpd-vhost.conf
<Directory "C: \ test">
Options indexes followsymlinks between des execcgi
AllowOverride all
Order allow, deny
Allow from all
</Directory>
You can also do this:
Find the following content in httpd. conf:
<Directory/>
Options followsymlinks
AllowOverride none
Order deny, allow
Deny from all
</Directory>
This is the default setting of Apache. The last line is like this.
Deny from all
This means that all access to the root directory is denied and others cannot access your website,
So you need to change it
Allow from all
However, it is recommended to use the first method, that is, to modify the content of the httpd-vhost.conf, this is clearer, it is safer.
In this way, Apache configuration is complete, but the following step is required.
3. There are also key steps:
This step is not required, because your local machine does not have DNS resolution.
Find the hosts file under the c: \ windows \ system32 \ drivers \ etc directory.
Add such a record
127.0.0.1 demoa-this is your domain name. How many virtual hosts do you need to add such records.
OK. Now you can set n + 1 domain name.
You can also refer to this address: http://httpd.apache.org/docs/2.0/vhosts/examples.html
Example:
--------------------------------------------------------------------------
<Virtualhost *: 80>
Serveradmin webmaster@dummy-host.localhost
DocumentRoot/www/docs/dummy-host.localhost
Servername dummy-host.localhost
Serveralias www. dummy-host.localhost
Errorlog logs/dummy-host.localhost-error_log
Customlog logs/dummy-host.localhost-access_log common
</Virtualhost>
<Virtualhost *: 80>
Serveradmin webmaster@dummy-host2.localhost
DocumentRoot/www/docs/dummy-host2.localhost
Servername dummy-host2.localhost
Errorlog logs/dummy-host2.localhost-error_log
Customlog logs/dummy-host2.localhost-access_log common
</Virtualhost>
<Directory "D: \ phpwork">
Options indexes followsymlinks between des execcgi
AllowOverride all
Order allow, deny
Allow from all
</Directory>
<Virtualhost *: 80>
Serveradmin webmaster@dummy-host2.localhost
DocumentRoot D: \ phpwork
Servername localhost
Errorlog logs/dummy-host2.localhost-error_log
Customlog logs/dummy-host2.localhost-access_log common
</Virtualhost>
<Directory "D: \ phpwork \ phpMyAdmin">
Options indexes followsymlinks between des execcgi
AllowOverride all
Order allow, deny
Allow from all
</Directory>
<Virtualhost *: 80>
Serveradmin webmaster@dummy-host2.localhost
DocumentRoot D: \ phpwork \ phpMyAdmin
Servername phpMyAdmin. Local
Errorlog logs/dummy-host2.localhost-error_log
Customlog logs/dummy-host2.localhost-access_log common
</Virtualhost>
<Directory "D: \ phpwork \ test">
Options indexes followsymlinks between des execcgi
AllowOverride all
Order allow, deny
Allow from all
</Directory>
<Virtualhost *: 80>
Serveradmin webmaster@dummy-host2.localhost
DocumentRoot D: \ phpwork \ test
Servername test. Local
Errorlog logs/dummy-host2.localhost-error_log
Customlog logs/dummy-host2.localhost-access_log common
</Virtualhost>
Original reprinted address: http://hi.baidu.com/xiyi2008/item/ebfc92001cd6cc10cd34ea64