One or two ways: domain -based virtual host and IP address -based virtual host (here based on the former)
Second, the role: implementation under the same Web server, running many sites (projects) at the same time
Third, the configuration of the virtual host
1. load the virtual host configuration file in the core configuration file
In Apache, the default is to provide a configuration file conf/extra/httpd-vhosts.conf that specifically configures the virtual host, but Apache will only read the core configuration file conf/httpd.conf when it starts. Therefore, you need to open it: in httpd.conf , find the Include conf/extra/httpd-vhosts.conf and remove the previous comment "#".
2. Create a virtual host in the configuration file of a virtual host
<virtualhost *:80>
ServerName//server name (domain name) Example: www.itcast.com
DocumentRoot//Document Root example: "H:/jiuyeban/homepage"
</VirtualHost>
3, configure the browser side of the domain name resolution
Change of local hosts file, the domain name and the IP address corresponds. The Hosts file path is: C:\Windows\System32\drivers\etc\hosts, or in the run inside input: Drivers, re-enter etc also can find the hosts file.
Note: If a virtual host is configured, the original default document root is changed, overwritten by the first virtual host, or if you do not want to be changed, either modify or reconfigure a host.
Iv. Directory access rights
1. When we visit a directory, there are three possible scenarios:
The first type: direct access to a default page;
The second type: Display file list;
The third type: Forbidden
2, in Apache , the default is deny from all , if you want to open a directory, you need to configure separately.
<directory " Catalogue ">
Allow from all
directoryindex index.html index.php default.php// Configure the index page ( Set default home page )
Options Indexes// Allow List of impressions ( whether to allow directory structure to be listed when setting default home Page cannot be displayed )
</directory >
to easy to manage, It is common practice to put this configuration directive together with the virtual host.
V. Decentralized configuration files
1. dispersed to Apache The configuration files for each directory are valid only for that directory and for subdirectories of that directory. Because there are things that you do not want users to have direct access to, set permissions separately.
the name of the distributed configuration file: . htaccess
2. . htaccess features of the file: In this configuration file Apache configuration does not require a restart APACHC service.
Main role: Domain redirection, anti-theft chain, custom error page.
. htaccess the file has the highest priority and can write any host-related configuration
3. in the master configuration file (virtual host httpd-vhosts.conf ), specify which directory can use the distributed configuration file
in the corresponding <directory "catalogue" ></Directory>, use allowoverride sets whether external configuration files are turned on ( . htaccess ), all or none
4. Other Settings
Order//Set access permissions for the current directory
Order Allow, deny// reject all without explicit permission
Order deny, allow// all allow if there are no explicit Deny entries
in the Apache , the default is deny from all , if you want to open a directory, you need to configure it separately.
Configuration of virtual hosts in Apache