tomcat的配置

设置tomcat管理帐号:

$CATALINA_HOME/conf/tomcat-users.xml文件内容修改如下:

<?xml version='1.0' encoding='utf-8'?>

<tomcat-users>
  
<role rolename="tomcat"/>
  
<role rolename="role1"/>
  
<user username="tomcat" password="tomcat" roles="tomcat"/>
  
<user username="role1" password="tomcat" roles="role1"/>
  
<user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>

设置默认tomcat web应用(站点):

How do I make my web application be the Tomcat default application ?

Congratulations.You have created and tested a first web application (traditionally called "mywebapp"), users can access it via the URL "http://myhost.company.com/mywebapp". You are very proud and satisfied. But now, how do you change the setup, so that "mywebapp" gets called when the user enters the URL "http://myhost.company.com" ?

The pages and code of your "mywebapp" application currently reside in (CATALINA_BASE)/webapps/mywebapp/. In a standard Tomcat installation, you will notice that under the same directory (CATALINA_BASE)/webapps/, there is a directory called ROOT (the capitals are important, even under Windows). That is the residence of the current Tomcat default application, the one that is called right now when a user calls up "http://myhost.company.com[:port]". The trick is to put your application in it's place.

First stop Tomcat.
Then before you replace the current default application, it may be a good idea to make a copy of it somewhere else.
Then delete everything under the ROOT directory, and move everything that was previously under the (CATALINA_BASE)/webapps/mywebapp/ directory, toward this (CATALINA_BASE)/webapps/ROOT directory. In other words, what was previously .../mywebapp/WEB-INF should now be .../ROOT/WEB-INF (and not .../ROOT/mywebapp/WEB-INF).

Just by doing this, you have already made you webapp into the Tomcat default webapp.

One step is left : you also need to have, within your application, a default servlet. This, you do by means of an appropriate url-mapping in the WEB-INF/web.xml configuration file of your application. Make sure you have something like this in that file :

    <servlet>
        
<servlet-name>My First Servlet</servlet-name>
        
<servlet-class>my.Servlet.Number1</servlet-class>
    
</servlet>

    
<servlet-mapping>
        
<servlet-name>My First Servlet</servlet-name>
        
<url-pattern>/*</url-pattern>
    
</servlet-mapping>

Restart Tomcat and you're done.
Call up "http://myhost.company.com/" and enjoy.

Addendum 1 : If you are deploying your application as a war file..

The above instructions relate to the situation where you are "manually" deploying your application as a directory-and-files structure under the /webapps directory. If instead you are using the "war" method to deploy your application, the principle is about the same :
- delete the ROOT directory
- name your war file "ROOT.war" (capitals mandatory)
- drop the ROOT.war file directly in the /webapps directory.
Tomcat will automatically deploy it.

For more information about this topic in general, consult this page : The Context Container

Addendum 2 : If for some reason you want another method..

If, for some reason, you do not want to deploy your application under the CATALINA_BASE/webapps/ROOT subdirectory, or you do not want to name your war-file "ROOT.war", then read on. But you should first read this : The Context Container and make sure you understand the implications.

The method described above is the simple method. The two methods below are more complex, and the second one has definite implications on the way you manage and run your Tomcat.

Method 2.1

- Place your war file outside of CATALINA_BASE/webapps (it must be outside to prevent double deployment).
- Place a context file named ROOT.xml in CATALINA_BASE/conf/<engine name>/<host name>. The single <Context> element in this context file MUST have a docBase attribute pointing to the location of your war file. The path element should not be set - it is derived from the name of the .xml file, in this case ROOT.xml. See the Context Container above for details.

Method 2.2

If you really know what you are doing..

- leave your war file in CATALINA_BASE/webapps, under its original name
- turn off autoDeploy and deployOnStartup in your Host element in the server.xml file.
- explicitly define all application Contexts in server.xml, specifying both path and docBase. You must do this, because you have disabled all the Tomcat auto-deploy mechanisms, and Tomcat will not deploy your applications anymore unless it finds their Context in the server.xml.

Note that this last method also implies that in order to make any change to any application, you will have to stop and restart Tomcat.

原文地址:https://www.cnblogs.com/moonson/p/1310043.html