Tomcat virtual directory and virtual host configuration / build a Web site (emphasis)

Solve Tomcat flash back a new way is to see if there does not exist a path or the wrong path name in server.xml


Configure the virtual directory in the server.xml file

<Host name="localhost"  appBase="E:\demoss" unpackWARs="true" autoDeploy="true">
        <Context path="/demoss" docBase="E:\demoss"/>

</Host>

The path attribute specifies the virtual path for Web applications, docBase attribute is used to specify the virtual path is mapped to a local file system directory.

Note that, server.xml modified file will not take effect immediately, you must restart the Tomcat server.

At the same time, the path docBase can not be wrong, if wrong Tomcat flash back phenomenon occurs.

So webapps directory can not demoss

However, docBase the directory must exist

This time you can visit http: // localhost: 8080 / demoss / aaa.html


Virtual Host Configuration

Tomcat server allows users to configure multiple Web sites on the same computer, in this case, you need to configure different host name for each Web site, that virtual host configuration.

Tomcat server disposed in the virtual host uses <Host> element, open server.xml Tomcat installation files directory found that one line of code as follows:

<Host name="localhost"  appBase="webapps"  unpackWARs="true"   autoDeploy="true">

<Host> element represents a virtual server, and the name attribute indicates the name and path of each appBase virtual host, in this case, it indicates the name of the virtual host localhost

, Path <Tomcat installation directory> \ webapps path. Then if you want to add a virtual host, only you need to add a server.xml in the <Engine> element

<Host> element, the storage directory site configured to correspond to the name of the host. For example, the D: \ demoss directory configured as a virtual host named demoss

Specific code as follows:

<Engine name="Catalina" defaultHost="localhost">
      <Host name="demoss"  appBase="E:\demoss" unpackWARs="true" autoDeploy="true">
        <Context path="/demoss" docBase="E:\demoss"/>

      </Host>
    </Engine>

In the above code using <Host> element is configured with a virtual host name demoss.

<Engine> defaultHost element has a property that specifies the default virtual host, i.e., if there is no access to the host, the host will be the default virtual access.

The demoss configured as the default virtual host specific codes are as follows:

<Engine name="Catalina" defaultHost="demoss">

</Engine>

It should be noted that the virtual hosts configured in order to be accessed by the outside world, must also be registered in the DNS (Domain Name System, the domain name system) server or a Windows system. Because access to a URL through a browser, you need to clear the corresponding host IP address, this IP to connect to the Web server. So, when the virtual host configuration is completed, still need host files to configure the mapping between virtual hosts and IP addresses.

Usually, the hosts file located in the root directory of the operating system under System32 \ drivers \ etc subdirectory, usually hosts the new version of win10 file system is blank, but we also can search the contents of the file before the Internet, reads as follows:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
#127.0.0.1 localhost
# ::1 localhost

So the content is full notes, the equivalent of an empty file.

We add a record in the following: 127.0.0.1 demoss

127.0.0.1 demoss role is to establish an IP address (127.0.0.1) and the host name (demoss) mapping relationship, so in this case you can access the local Web server by demoss in your browser. Then configure the line 127.0.0.1 demoss that is, D: \ demoss directory configured virtual host named demoss of.


Set up a Web site (emphasis)

(1): Create a directory in the root directory of E newhost, the application copied to develop good demoss newhost directory.

(2): increasing a <Host> element in the server.xml file, the name attribute of the element to www.newhost.com

appBase property to E: \ newhost, specific code as follows:

<Engine name="Catalina" defaultHost="localhost">

<Host name="www.newhost.com"  appBase="E:\newhost">

</Host>

</Engine>

Note Host inside and the beginning of the same, do not fill it add any element.

(3): configure the mapping between the virtual host and IP address in the hosts file in the Windows system, the specific code as follows:

127.0.0.1      www.new.host.com

(4): Restart the Tomcat server, enter http://www.newhost.com:8080/demoss/aaa.html access aaa.html page in the address bar of your browser.


appendix 

 

Published 98 original articles · won praise 43 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_42352666/article/details/105235846