Virtual Hosting and Tomcat

Tomcat Home
The Apache Software Foundation
Apache Tomcat 9
Version 9.0.34, Apr 3 2020
Links

Docs Home
FAQ
User Comments

User Guide

1) Introduction
2) Setup
3) First webapp
4) Deployer
5) Manager
6) Host Manager
7) Realms and AAA
8) Security Manager
9) JNDI Resources
10) JDBC DataSources
11) Classloading
12) JSPs
13) SSL/TLS
14) SSI
15) CGI
16) Proxy Support
17) MBeans Descriptors
18) Default Servlet
19) Clustering
20) Load Balancer
21) Connectors
22) Monitoring and Management
23) Logging
24) APR/Native
25) Virtual Hosting
26) Advanced IO
27) Mavenized
28) Security Considerations
29) Windows Service
30) Windows Authentication
31) Tomcat's JDBC Pool
32) WebSocket
33) Rewrite
34) CDI 2 and JAX-RS
35) GraalVM Support

Reference

Release Notes
Configuration
Tomcat Javadocs
Servlet 4.0 Javadocs
JSP 2.3 Javadocs
EL 3.0 Javadocs
WebSocket 1.1 Javadocs
JASPIC 1.1 Javadocs
Common Annotations 1.3 Javadocs
JK 1.2 Documentation

Apache Tomcat Development

Building
Changelog
Status
Developers
Architecture
Functional Specs.
Tribes

Virtual Hosting and Tomcat
Table of Contents

Assumptions
server.xml
Webapps Directory
Configuring Your Contexts
    General
    context.xml - approach #1
    context.xml - approach #2
    Defaults per host
    Further Information

Assumptions

For the sake of this how-to, assume you have a development host with two host names, ren and stimpy. Let’s also assume one instance of Tomcat running, so $CATALINA_HOME refers to wherever it’s installed, perhaps /usr/local/tomcat.

Also, this how-to uses Unix-style path separators and commands; if you’re on Windows modify accordingly.
server.xml

At the simplest, edit the Engine portion of your server.xml file to look like this:

Note that the directory structures under the appBase for each host should not overlap each other.

Consult the configuration documentation for other attributes of the Engine and Host elements.
Webapps Directory

Create directories for each of the virtual hosts:

mkdir $CATALINA_HOME/renapps
mkdir $CATALINA_HOME/stimpyapps

Configuring Your Contexts
General

Contexts are normally located underneath the appBase directory. For example, to deploy the foobar context as a war file in the ren host, use $CATALINA_HOME/renapps/foobar.war. Note that the default or ROOT context for ren would be deployed as $CATALINA_HOME/renapps/ROOT.war (WAR) or $CATALINA_HOME/renapps/ROOT (directory).

NOTE: The docBase for a context should never be the same as the appBase for a host.
context.xml - approach #1

Within your Context, create a META-INF directory and then place your Context definition in it in a file named context.xml. i.e. $CATALINA_HOME/renapps/ROOT/META-INF/context.xml This makes deployment easier, particularly if you’re distributing a WAR file.
context.xml - approach #2

Create a structure under $CATALINA_HOME/conf/Catalina corresponding to your virtual hosts, e.g.:

mkdir $CATALINA_HOME/conf/Catalina/ren
mkdir $CATALINA_HOME/conf/Catalina/stimpy

Note that the ending directory name “Catalina” represents the name attribute of the Engine element as shown above.

Now, for your default webapps, add:

$CATALINA_HOME/conf/Catalina/ren/ROOT.xml
$CATALINA_HOME/conf/Catalina/stimpy/ROOT.xml

If you want to use the Tomcat manager webapp for each host, you’ll also need to add it here:

cd $CATALINA_HOME/conf/Catalina
cp localhost/manager.xml ren/
cp localhost/manager.xml stimpy/

Defaults per host

You can override the default values found in conf/context.xml and conf/web.xml by specifying the new values in files named context.xml.default and web.xml.default from the host specific xml directory.

Following our previous example, you could use $CATALINA_HOME/conf/Catalina/ren/web.xml.default to customize the defaults for all webapps that are deployed in the virtual host named ren.
Further Information

Consult the configuration documentation for other attributes of the Context element.
Copyright © 1999-2020, The Apache Software Foundation

发布了133 篇原创文章 · 获赞 191 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/blog_programb/article/details/105730888
今日推荐