1.apr 
许多朋友可能在启动tomcat的时候都会看到类似这样的信息:

引用
org.apache.catalina.core.AprLifecycleListener init 
信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Java\jre\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS

出现这种情况是这表示没有找到APR 
简要解决办法:去 http://tomcat.heanet.ie/native/ 下载编译好的tcnative-1.dll文件,目前最新为1.1.14,拷贝至jdk\bin下,再启动就可以成功加载APR了。

引用
org.apache.catalina.core.AprLifecycleListener init 
信息: Loaded Apache Tomcat Native library 1.1.14. 
org.apache.catalina.core.AprLifecycleListener init 
信息: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], random [true].

2.URIEncoding 
有时候在做开发的时候经常发现文本框输入的中文到了程序中成了乱码,其实是因为在端口监听部分缺少编码。

  1. URIEncoding="UTF-8"

解决方法如下: 
原始部分 
8080端口上

  1. <Connector port="8080" protocol="HTTP/1.1"
  2. connectionTimeout="20000"
  3. redirectPort="8443" />

修改后

  1. <Connector port="8080" protocol="HTTP/1.1"
  2. connectionTimeout="20000"
  3. redirectPort="8443" URIEncoding="UTF-8" />

8009端口 ajp跳转服务上,关于这个端口在apache http 做跳转时,要相当注意

  1. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

修改后

  1. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />

这样,服务器得到的中文字符就不会再有乱码了。

3.设置Tomcat管理员帐号 
修改tomcat-users.xml文件,在</tomcat-users>的标签前添加一行

  1. <user username="tomcat" password="tomcat" roles="admin,manager"/>

让tomcat用户拥有管理员权限。

4.设置SSL 
首先,我们要创建密钥:

  1. keytool -genkey -alias tomcat -keyalg RSA

此时,用户主目录下会生成一个.keystore文件。 
然后,我们配置server.xml文件,找到SSLEnabled="true"所在的标签,将其解除注释,同时填补两个属性: 
    1.keystoreFile="C:/Users/Zlex/.keystore" 
    2.keystorePass="123456" 
keystoreFile 指的是你的密钥文件存储的路径,keystorePass指的是你的密码。 
举例如下:

  1. <!--
  2. Define a SSL HTTP/1.1 Connector on port 8443 This connector uses the
  3. JSSE configuration, when using APR, the connector should be using the
  4. OpenSSL style configuration described in the APR documentation
  5. -->
  6. <!-- -->
  7. <Connector
  8. SSLEnabled="true"
  9. clientAuth="false"
  10. keystoreFile="C:/Users/Zlex/.keystore"
  11. keystorePass="123456"
  12. maxThreads="150"
  13. port="8443"
  14. protocol="HTTP/1.1"
  15. scheme="https"
  16. secure="true"
  17. sslProtocol="TLS" />

最后,重启tomcat,在地址栏中访问 https://localhost:8443/。 
将上述port="8443"配置改为port="443",可以通过https://localhost/直接访问。 
需要双向认证?参考如下内容:

  1. <Connector port="443"
  2. URIEncoding="UTF-8"
  3. useBodyEncodingForURI="true"
  4. maxHttpHeaderSize="33192"
  5. maxThreads="150"
  6. minSpareThreads="25"
  7. maxSpareThreads="75"
  8. enableLookups="false"
  9. disableUploadTimeout="true"
  10. acceptCount="100"
  11. scheme="https"
  12. secure="true"
  13. SSLEnabled="true"
  14. clientAuth="true"
  15. keystoreFile="conf/server.keystore"
  16. keystorePass="123456"
  17. truststoreFile="conf/ca.p12"
  18. truststorePass="123456"
  19. truststoreType="PKCS12"
  20. sslProtocol="TLS" />

其中,

  1. clientAuth="true"
  2. keystoreFile="conf/server.keystore"
  3. keystorePass="123456"
  4. truststoreFile="conf/ca.p12"
  5. truststorePass="123456"
  6. truststoreType="PKCS12"

clientAuth="true"开启双向认证 
keystoreFile="conf/server.keystore" 指向服务器密钥库 
keystorePass="123456" 服务器密钥库密码 
truststoreFile="conf/ca.p12"指向CA信任库 
truststorePass="123456"CA信任库密码 
truststoreType="PKCS12"CA信任库格式,除了PKCS#12还有JKS,JKS为java原生默认支持的密钥库格式! 
更多ssl配置访问http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html

5.通过GZIP压缩加速服务器响应速度

只需要配置:

  1. <Connector
  2. port="8080"
  3. protocol="HTTP/1.1"
  4. connectionTimeout="20000"
  5. redirectPort="443"
  6. URIEncoding="UTF-8"
  7. compression="on"
  8. noCompressionUserAgents="gozilla, traviata"
  9. compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,application/json"
  10. />

说说配置细节: 
compression="on"   开启压缩支持 
noCompressionUserAgents="gozilla, traviata"   不压缩的内容 
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,application/json" 压缩的类型

之后进行的访问均可获得GZIP压缩支持

6.设置静态页面编码 
修改web.xml 
加入如下内容,是*.hml、*.html静态页面默认字符集编码为UTF-8

  1. <mime-mapping>
  2. <extension>htm</extension>
  3. <mime-type>text/html;charset=utf-8</mime-type>
  4. </mime-mapping>
  5. <mime-mapping>
  6. <extension>html</extension>
  7. <mime-type>text/html;charset=utf-8</mime-type>
  8. </mime-mapping>

7.配置JVM 
找到JAVA_OPTS进行配置:

    1. JAVA_OPTS="-Xms512m -Xmx512m -XX:MaxPermSize=256m -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8"

Tomcat 优化的更多相关文章

  1. tomcat优化

    tomcat优化:vim catalina.sh添加:JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -X ...

  2. windows tomcat 优化

    windows tomcat 优化 1.  tomcat conf server.xml 在server.xml中修改以一部分,增加节点数目,可以很好的提高性能: <Connector port ...

  3. Tomcat 优化 java.lang.OutOfMemoryError: Java heap space 的解决方法

    Tomcat 优化 java.lang.OutOfMemoryError: Java heap space 的解决方法 java.lang.OutOfMemoryError: Java heap sp ...

  4. tomcat优化-有改protocol 和 缓存 集群方案

    tomcat优化 在线上环境中我们是采用了tomcat作为Web服务器,它的处理性能直接关系到用户体验,在平时的工作和学习中,归纳出以下七种调优经验. 1. 服务器资源 服务器所能提供CPU.内存.硬 ...

  5. tomcat 优化配置 java-8 tomcat-7

    tomcat 优化配置 , 说明 一.并发优化 1.JVM调优 以下为1G物理内存tomcat配置: JAVA_OPTS="-server -Xms512M -Xmx512M -Xss256 ...

  6. Tomcat 优化方案 和 配置详解(转)

    转自 Tomcat 优化方案 和 配置详解 http://201605130349.iteye.com/blog/2298985 Server.xml配置文件用于对整个容器进行相关的配置. <S ...

  7. Tomcat优化之容易集合经验

    Tomcat优化1. 如何加大tomcat连接数在tomcat配置文件server.xml中的<Connector ... />配置中,和连接数相关的参数有: maxThreads : t ...

  8. tomcat优化实例

    ———————————————————————————————————— 一.运行模式优化 修改tomcat运行模式为nio<Connector port="80" prot ...

  9. tomcat优化之安装并配置apr库

    在谈到tomcat优化时,必然要说到apr库,这个库是C语言实现的,tomcat通过JNI方式使用该库可以大大提高性能. tomcat在使用apr时需要安装apr,apr-util和tomcat-na ...

  10. tomcat优化和JVM修改内存

    Tomcat中的线程池(APR和ThreadPool) 2. 在Connector中指定使用共享线程池: <Connector executor="tomcatThreadPool&q ...

随机推荐

  1. SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-002- Spring的JSP标签之form标签(<sf:input><sf:errors><sf:form>)

    一. Spring offers two JSP tag libraries to help define the view of your Spring MVC web views. One tag ...

  2. ruby quiz The Solitaire Cipher

    solitaire cipher:http://en.wikipedia.org/wiki/Solitaire_(cipher) https://www.schneier.com/solitaire. ...

  3. Android开发之permission

    permission,Android权限系统. 基本上都是在manifest.xml文件中进行操作. 1.申请使用权限 申请使用权限使用标记:<uses-permission /> 比如申 ...

  4. Hadoop源代码分析【IO专题】

    由于Hadoop的MapReduce和HDFS都有通信的需求,需要对通信的对象进行序列化.Hadoop并没有采用Java的序列化(因为Java序列化比较复杂,且不能深度控制),而是引入了它自己的系统. ...

  5. Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces

    问题解决:缺少jar包 cglib-2.1.3.jar

  6. WIKIOI 1222信与信封问题

    题目描述 Description John先生晚上写了n封信,并相应地写了n个信封将信装好,准备寄出.但是,第二天John的儿子Small John将这n封信都拿出了信封.不幸的是,Small Joh ...

  7. 让ASP.NET MVC页面返回不同类型的内容

    在ASP.NET MVC的controller中大部分方法返回的都是ActionResult,更确切的是ViewResult.它返回了一个View,一般情况下是一个HTML页面.但是在某些情况下我们可 ...

  8. CefSharp中实现Chrome中jS导出Excel

    [前言] 在博客园闲逛了一年多,平时都是借鉴别人的成功经验,总觉得自己应该分享点什么,但是苦于自己技术有限,平时又不爱写东西,所以一直没有写过任何东西.毕业一年多,在现实工作中遇到各种问题,深切体会到 ...

  9. [NOIP2011]瑞士轮

    noip2011普及组第3题. 题目背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平 ...

  10. while MyJob = '程序员' do --- 序

    因为自己的际遇,忽然想写点什么留在这个世上.也许只是想证明自己活过吧. 所以,这不会是一个过去时的小说,这将是一个接近进行时的记叙.之所以是接近,因为我只有在空余时间,才能记录最近的经历.出于保护隐私 ...