REST应用减配
如上图所示,在默认情况下,Tomcat启用了org.apache.catalina.servlets.DefaultServlet
和org.apache.jasper.servlet.JspServlet
来分别对静态资源和JSP进行处理。而在时下流行的微服务架构中,应用通常采用前后端分离的设计,后端的功能通过REST API
方式向前端提供服务。针对REST应用,我们可以将该两项配置禁用掉,即将${TOMCAT_HOME}/conf/web.xml
配置文件中的以下内容注释掉:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
禁用AccessLogValve
在Nginx代理服务器中已经记录了AccessLog日志,所以在Tomcat应用服务器中没必要再记录一份,可以将${TOMCAT_HOME}/conf/server.xml
配置文件中的以下内容注释掉:1
2
3<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
线程池配置
1 | <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" |
温馨提示:配置后可通过JDK自带的
jconsole
监视工具观察配置是否生效。