A virtual host is one that runs multiple websites (for example company1.example.com
, and) on a single machine company2.example.com
. A virtual host can be "IP-based", that is, one site per IP, or "Based on name", that is, multiple sites per IP. The fact that these sites run on the same physical server is not clearly disclosed to the end user. -This is the official website explanation.
Configure the Apache virtual host. (Httpd-vhosts.conf--apache virtual Host configuration file)
Name-based virtual hosts (multiple sites per IP)
<virtualhost *:80> # This first-listed virtual host was also the default for *:80 ServerName www.example.com< C8/>serveralias example.com documentroot/www/domain</virtualhost><virtualhost *:80> ServerName other.example.com documentroot/www/otherdomain</virtualhost>
noun explanation:
VirtualHost: Refers to the ip/domain name of the virtual host, *:80 represents all IPs representing all 80 ports
ServerName: Virtual host Name
Serveralias: Virtual host alias, host alias can be multiple support wildcard characters
Serveralias Example . *. Example . com
DocumentRoot: Site Directory
IP-based virtual hosts (one site per IP)
Listen 172.20.30.40:80<virtualhost 172.20.30.40:80> ServerAdmin [email protected] documentroot/www/ VHOSTS/WWW1 ServerName www1.example.com errorlog/www/logs/www1/error_log customlog/www/logs/www1/ Access_log combined</virtualhost> <pre name= "code" class= "plain" >listen 172.20.30.50:80<virtualhost 172.20.30.50:80> ServerAdmin [email protected] DOCUMENTROOT/WWW/VHOSTS/WWW2 ServerName www2.example.org errorlog/www/logs/www2/error_log customlog/www/logs/www2/access_log combined</ Virtualhost>
noun explanation :
<pre name= "code" class= "plain" >serveradmin Webmaster mailbox <pre name= "code" class= "plain" ><pre name= "code "Class=" plain ">errorlog error log <pre name=" code "class=" plain "><pre name=" code "class=" plain "> Customlog Access Log
Enable Apache Virtual Host feature (httpd.conf)
Search the Virtual hoststo get rid of the conf/extra/httpd-vhosts.conf in front of #Include
# Virtual Hosts#include conf/extra/httpd-vhosts.conf
Restart Apache Service
Apache 2.4 Virtual Host Configuration