apache2.2.x version
1. Note The doucumentroot in the master configuration file/etc/httpd/conf/httpd.conf
" /var/www/html "
2. Remove the main configuration file namevirtualhost the previous comment, add the local host name
192.168. 136.131:
3. If the servername is commented, or the default is localahost:80 or 127.0.0.1:80, it will be an error, but does not affect the use of the virtual host
" stopping httpd: [ OK ]starting httpd:httpd:Could not reliably determine the server's fully qualified domain NA Me, using:: 1 for ServerName [ OK ]
4. Add a configuration file for the virtual host below the Master profile
<virtualhost192.168.136.131: the>//Local Host name, this user-authenticated loginDocumentroot/var/www/virtual/test1//Site root directoryServerName www.test1.com//Domain 1Errorlog logs/error_logs//Error Log AddressCustomlog Logs/custom_logs combined//General log, combined type record<Directory/var/www/virtual/test1/>//Configure Site Directory permissionsOptions none#allowoverride None allowoverride authconfig//Add Base user Authentication login configurationauthtype Basic AuthName"Test"AuthUserFile"/etc/httpd/conf/htpasswd" //Authentication User Password storage locationRequire User Test//allow only Test loginOrder Allow,deny//allow all users to access allow from all</directory></virtualhost><virtualhost192.168.136.131: the>//General ConfigurationServerAdmin [email protected]//Domain 2documentroot/var/www/virtual/test2/ServerName www.test2.com errorlog logs/Error_logs</VirtualHost>
Then restart httpd
httpd2.4.x version
1. The main configuration file only need to virtualhost the following incalude line to remove comments
/etc/httpd/extra/httpd-vhosts.conf
2. Configure/etc/httpd/extra/httpd-vhost.conf
<virtualhost *: the>//Do not fill in 127.0.0.1 or localhost here, you can use the "*" or the local network IP extranet IPServerAdmin [email protected] documentroot"/usr/local/apache/htdocs/www.a.org"ServerName"www.a.org"directoryindex index.html index.php errorlog"Logs/www.a.org-error_log"Customlog"Logs/www.a.org-access_log"combined</virtualhost><virtualhost *: the>ServerAdmin [email protected] documentroot"/usr/local/apache/htdocs/www.b.org"ServerName"www.b.org"directoryindex index.html index.php errorlog"Logs/www.b.org-error_log"Customlog"Logs/www.b.org-access_log"combined</VirtualHost>
3. Restart the service
HTTPD Virtual host configuration based on different domain names