Use Apache to configure a virtual host to run multiple Web sites on a single system.
Many Linux hosts now use Apache as a Web server, most of which are based on this principle to configure virtual hosts.
Below is a tutorial on using Apache 2.4.3 as a demonstration under Windows.
Here is simply a brief description of the principle of implementation
1.Apache configuration file httpd.conf, find virtual hosts, make the following changes to save.
# virtual Hosts#include conf/extra/httpd-vhosts.conf Remove the ' # ' from line 2nd and change to # virtual Hostsinclude conf/extra/httpd-vhosts.conf
This opens the extra folder under the Httpd-vhosts.conf, later modify the virtual host as long as in this file.
2. Configure the httpd-vhosts.conf.
such as domain names www.a.com and www.b.com
# virtual hosts## required modules: mod_log_config# if you want to maintain multiple domains/hostnames on your# machine you can Setup virtualhost containers for them. most configurations# use only &NBSP;NAME-BASED&NBSP;VIRTUAL&NBSP;HOSTS&NBSP;SO&NBSP;THE&NBSP;SERVER&NBSP;DOESN ' t need to Worry about# ip addresses. this is indicated by the asterisks in the directives below.## Please see the documentation at # <url:http://httpd.apache.org/docs/2.4/vhosts/># for further details before you try to setup virtual hosts.## You may use the command line option '-S ' to verify your virtual host# Configuration.## virtualhost eXample:# almost any apache directive may go into a virtualhost container.# The first VirtualHost section is used for all requests that do not# match a servername or serveralias in Any <virtualhost> block.#<virtualhost *:80> serveradmin [email protected] DocumentRoot "d:/www/a" servername a.com serveralias www.a.com errorlog " Logs/a.com.log " CustomLog " Logs/a.com.log " common < directory "d:/www/a" > Require all granted </Directory> </VirtualHost><VirtualHost *:80> serveradmin&nBsp [email protected] documentroot "D:/www/b" servername b.com ServerAlias www.b.com ErrorLog "logs/ B.com.log " CustomLog " Logs/b.com.log " common < directory "D:/www/b" > Require all granted </Directory> </VirtualHost>
Note: Apache you need to add Require all granted below the directory in the 2.4 or later versions, otherwise the access is 403.
This I also looked for a long time to find out the reason, the official documents did not find a description of the place.
Build Apache Virtual Host (vhost) configuration