Reference: http://jingyan.baidu.com/article/363872ec870f6e6e4ba16feb.html
There are eight scenarios in which Apache virtual hosts are configured based on different scenarios. First look at what kind of situation your virtual host belongs to, and then it's OK. The process is not complex, the key lies in the remedy. How to configure Apache virtual host steps/method IP address-based virtual host listen the<virtualhost172.20.30.40>DocumentRoot/home/httpd/html1servername Www.ok1.comErrorLog/usr/local/apache/logs/Error1_logcustomlog/usr/local/apache/logs/Access1_log Combined</virtualhost><virtualhost172.20.30.50>DocumentRoot/home/httpd/html2servername Www.ok2.comErrorLog/usr/local/apache/logs/Error2_logcustomlog/usr/local/apache/logs/Access2_log Combined</VirtualHost>IP and multi-port-based virtual host configuration Listen172.20.30.40: theListen172.20.30.40:8080Listen172.20.30.50: theListen172.20.30.50:8080<virtualhost172.20.30.40: the>DocumentRoot/www/example1- theServerName www.example1.com</virtualhost><virtualhost172.20.30.40:8080>DocumentRoot/www/example1-8080ServerName www.example1.com</virtualhost><virtualhost172.20.30.50: the>DocumentRoot/www/example2- theServerName www.example1.org</virtualhost><virtualhost172.20.30.50:8080>DocumentRoot/www/example2-8080ServerName www.example2.org</VirtualHost>How to configure a domain-based virtual host configuration on a server with a single IP address for Apache Virtual Host # Ensure that Apache listens on port theListen the# Listen for Virtualhost requests on all IP Addressesnamevirtualhost*: the<virtualhost *: the>DocumentRoot/www/example1servername www.example1.comServerAlias example1.com.*. example1.com# other Directives here</virtualhost><virtualhost *: the>DocumentRoot/www/Example2servername www.example2.org# Other directives here</VirtualHost>Configure a domain-based virtual host on a server with multiple IP addresses listen the# This isThe"Main"Server running on172.20.30.40ServerName Server.domain.comDocumentRoot/www/mainserver# This isThe other addressnamevirtualhost172.20.30.50<virtualhost172.20.30.50>DocumentRoot/www/Example1servername www.example1.com# Other directives ...</virtualhost><virtualhost172.20.30.50>DocumentRoot/www/Example2servername www.example2.org# Other directives ...</VirtualHost>run different sites on different ports (configure domain-based virtual hosts on a multi-port-based server) Listen theListen8080Namevirtualhost172.20.30.40: theNamevirtualhost172.20.30.40:8080<virtualhost172.20.30.40: the>ServerName Www.example1.comDocumentRoot/www/domain- the</virtualhost><virtualhost172.20.30.40:8080>ServerName Www.example1.comDocumentRoot/www/domain-8080</virtualhost><virtualhost172.20.30.40: the>ServerName Www.example2.orgDocumentRoot/www/otherdomain- the</virtualhost><virtualhost172.20.30.40:8080>ServerName Www.example2.orgDocumentRoot/www/otherdomain-8080</VirtualHost>configuration of listen based on domain name and IP-based hybrid virtual host theNamevirtualhost172.20.30.40<virtualhost172.20.30.40>DocumentRoot/www/example1servername www.example1.com</virtualhost><virtualhost172.20.30.40>DocumentRoot/www/example2servername www.example2.org</virtualhost><virtualhost172.20.30.40>DocumentRoot/www/example3servername www.example3.net</VirtualHost>
Configure Apache Virtual Host