I. Modification of httpd.conf
Open the Appserv installation directory, locate the httpd.conf file, and remove the # number in front of the two lines below.
[plain] view plain copy #LoadModule vhost_alias_module modules/mod_vhost_alias.so Remove # means the virtual Host feature that enables Apache.
[plain] view plain copy #Include conf/extra/httpd-vhosts.conf remove this line of # meaning from conf/extra/ httpd-vhosts.conf this file into the virtual host configuration
ii. modification of httpd-vhosts.conf
Open the file and see the following similar content. The configuration of the virtual host is also configured with reference to the following content. The following is an explanation of the content
[plain] view plain copy namevirtualhost *:80 <virtualhost *:80> ServerAdmin T.www.phpstudy.net documentroot "C:/Program files/apache2/docs/dummy-host.www.phpstudy.net" ServerName dummy-h Ost.www.phpStudy.net serveralias www.dummy-host.www.phpStudy.net ErrorLog "Logs/dummy-host.www.phpstudy.net-er Ror.log "Customlog" Logs/dummy-host.www.phpstudy.net-access.log "Common </VirtualHost> namevirtualhost *:8 0
Note 1:namevirtualhost Specifies the IP address or domain name used by the virtual host, but preferably the IP address. Namevirtualhost is a necessary instruction when using a domain based virtual host. Namevirtualhost can define multiple.
NOTE 2: All requests that conform to the namevirtualhost or <VirtualHost> tag definitions are treated as virtual hosts and the primary server will ignore them. Namevirtualhost defines a request that is not defined by the <VirtualHost> tag, the server cannot find the corresponding virtual host and will not be able to handle it. So each namevirtualhost-defined parameter must have at least one <VirtualHost> match.
Note 3: If you set Namevirtualhost or <VirtualHost> *:80, all requests for port 80 will be processed by the virtual host, and the request will point to a virtual host based on the domain name. If there is a request from port 80, and the requested domain name is not configured as a virtual host, it will point to the first virtual host. This will make it impossible for the primary server to receive any requests from port 80. To do this, you also configure a virtual host for the primary server.
ServerAdmin Administrator Mailbox
DocumentRoot Site Directory (note: If the path in the site directory has spaces, enclose the path with double quotes)
ServerName the domain name to bind (required)
Serveralias the alias of the virtual host to bind to. (optional, if more than one domain name, the middle is separated by a space, if not, then remove the line)
Support *,? Two wildcard characters, such as *.abc.com, indicate that any one abc.com level two domain name is accessible.
Customlog user log file (optional, if not required, remove the line)
ErrorLog error log (optional, if not required, remove the line)
virtual host based on IP address
[plain] view plain copy <virtualhost 172.20.30.40> documentroot/www/example1 ServerName www.examp le.com </VirtualHost> [plain] view plain copy <virtualhost 172.20.30.50 192.168.0.10:80> Doc Umentroot/www/example2 ServerName www.example.org </VirtualHost> Each virtual host can define multiple IP, separated by a space
mixed use of various virtual hosts
[Plain] View plain copy listen 80 listen 81 namevirtualhost 172.20.30.40 <VirtualHost 172.20.30.40> documentroot /www/example1 ServerName www.example.com </VirtualHost> <VirtualHost 172.20.30.40> DocumentRoot /www/example2 servername www.example.org </VirtualHost> namevirtualhost 172.20.30.40:81 <VirtualHost 172.20.30.40:81> documentroot /www/ example3 ServerName www.example3.net </VirtualHost> # ip-based <VirtualHost 172.20.30.50> & nbsp; documentroot /www/example4 ServerName www.example4.edu </VirtualHost> <virtualhost 172.20.30.60:81 172.20.30.40:81>