Tomcat5.5.x配置整理

作者在 2007-10-12 19:15:00 发布以下内容
1.下载:
jakarta-tomcat-5.5.x.zip
jakarta-tomcat-5.5.x-compat.zip
jakarta-tomcat-5.5.x-admin.zip
(Tomcat 默认是没有内置admin模块了
Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it. )
都解压到同一个目录下面。比如:D:\jakarta-tomcat-5.5.x\
(如果使用jdk1.4,才需要compat.zip用jdk1.5就可以免了这个。)
 
2.修改jakarta-tomcat-5.5.x\conf\tomcat-users.xml.
添加管理员账号lizongbo,密码为lizongbopass.
新xml如下:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="lizongbo" password="lizongbopass" roles="admin,manager"/>
</tomcat-users>
 
3.修改jakarta-tomcat-5.5.x\conf\server.xml来解决编码问题。
(给Connector 添加URIEncoding参数,参考http://blog.csdn.net/darkxie/archive/2004/10/25/TOMCATAPP.aspx)
(可以设置成GB18030)
    <Connector port="8080"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="200"
               connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"
               compression="on" compressionMinSize="2048"
      noCompressionUserAgents="gozilla, traviata"
      compressableMimeType="text/html,text/xml"/>
 
    <Connector port="8009"
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" URIEncoding="GBK"/>
 

4.启用支持gzip压缩.
(
技术文章 | 阅读 1982 次
文章评论,共3条
zl芊芊zl(作者)
2007-10-12 19:16
1

 
 9.指定了自己的javaEncoding
(参考 http://gceclub.sun.com.cn/staticcontent/html/sunone/app7/app7-dg-webapp/ch6/ch6-4.html )

    <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>javaEncoding</param-name>
            <param-value>GB18030</param-value>
        </init-param>
        <init-param>
            <param-name>xpoweredBy</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
    </servlet>
 10.添加rar,iso等的mime-type映射 
避免在浏览器里直接打开。
<mime-mapping>
<extension>mht</extension>
<mime-type>text/x-mht</mime-type>
</mime-mapping>
<mime-mapping>
        <extension>rar</extension>
        <mime-type>application/octet-stream</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>iso</extension>
        <mime-type>application/octet-stream</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>ape</extension>
        <mime-type>application/octet-stream</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>rmvb</extension>
        <mime-type>application/octet-stream</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>ico</extension>
        <mime-type>image/x-icon</mime-type>
    </mime-mapping>
10.1对html静态页面设置编码
<!--  修改下面两行以支持静态超文本的自动编码 
  --> 
 <mime-mapping>
  <extension>htm</extension> 
  <mime-type>text/html;charset=gb2312</mime-type> 
  </mime-mapping>
 <mime-mapping>
  <extension>html</extension> 
  <mime-type>text/html;charset=gb2312</mime-type> 
  </mime-mapping>
  </web-app>
 
11.添加welcome-file-list,并调整顺序。
 <welcome-file-list>    
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

12.如果你的webapp需要只能够进行https方式访问,那么在webapp的web.xml里加上:
 <security-constraint>
  <web-resource-collection>
   <web-resource-name>must https</web-resource-name>
   <url-pattern>/lizongbo/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
   <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
 </security-constraint>
参考:http://jakarta.apache.org/tomcat/faq/security.html#https
http://marc.theaimsgroup.com/?l=tomcat-user&m=104951559722619&w=2
13.修改远程关闭服务器的命令。
server.xml默认有下面一行:
<Server port="8005" shutdown="SHUTDOWN">
这样允许任何人只要telnet到服务器的8005端口,输入"SHUTDOWN",然后回车,服务器立即就被关掉了。
从安全的角度上考虑,我们需要把这个shutdown指令改成一个别人不容易猜测的字符串。
例如修改如下:
<Server port="8006" shutdown="lizongbo">,这样就只有在telnet到8006,并且输入"lizongbo"才能够关闭Tomcat.
注意:这个修改不影响shutdown.bat的执行。运行shutdown.bat一样可以关闭服务器。
参考:http://jakarta.apache.org/tomcat/faq/security.html#8005
 
 
以下皆可以参考:http://www.cnjsp.org/document/user/tuman/valve.html
 
 
14.配置http访问日志。Tomcat自带的能够记录的http访问日志已经很详细了
取消下面这段的注释:
 
        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>
 
然后修改为:
        <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
                 pattern="combined" resolveHosts="false" fileDateFormat="yyyy-MM-dd.HH"/>
 
pattern="combined" 记录的日志内容更详细,fileDateFormat="yyyy-MM-dd.HH",会让日志文
zl芊芊zl(作者)
2007-10-12 19:18
2
15.限制ip,限制主机访问等。
如果想禁止指定的ip或者主机名来拒绝某些机器访问,或者指定某些机器来访问。
也支持分别按Engine, Host, or Context,进行以下配置:
<Context path="/examples" ...>  ...
  <Valve className="org.apache.catalina.valves.RemoteHostValve"
         allow="*.mycompany.com,www.yourcompany.com"/>
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         deny="192.168.1.*"/>
</Context>
参考:
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/context.html
 
16.发布webapp到网站根目录
1。直接复制到ROOT目录下。
2.因为无法创建无名字的xml文件,并且在xml文件里指定path也是无效的(tomcat靠文件名字来判断的),
因此必须在server.xml里写下面一段:
<Context docBase="${catalina.home}/vhost/www.lizongbo.com" path="/"
         privileged="true" antiResourceLocking="false" antiJARLocking="false">
<Manager className="org.apache.catalina.session.StandardManager" algorithm="SHA-512" 
entropy="suijisifuchuansuijisifuchuansuijisifuchuansuijisifuchuan"
maxActiveSessions="800" /> 
        <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
                 directory="logs"  prefix="localhost_mytest_access_log." suffix=".txt"
                 pattern="combined" resolveHosts="true" fileDateFormat="yyyy-MM-dd.HH"/>        
 
</Context>
而且必须把ROOT目录删除掉,否则Tomcat还是优先部署ROOT目录为"/"。
 
17.在重新启动Tomcat的webapp的时候,禁止把session写入文件。
修改conf/web.xml
取消注释:
 <!---->
    <Manager pathname="" />
 
18.增强SessiionID的生成算法和长度。
 

         <Manager className="org.apache.catalina.session.StandardManager" algorithm="SHA-512" sessionIdLength="40">
         </Manager>
 
(默认的是MD5,长度是16位。)
 
19.配置日志:(http://jakarta.apache.org/tomcat/tomcat-5.5-doc/logging.html)
 
在D:\jakarta-tomcat-5.5.8\common\classes\新建log4j.properties 
 
内容:
log4j.rootLogger=debug, R 
log4j.appender.R=org.apache.log4j.RollingFileAppender 
log4j.appender.R.File=${catalina.home}/logs/tomcat5.5.log 
log4j.appender.R.MaxFileSize=10MB 
log4j.appender.R.MaxBackupIndex=10 
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n 
log4j.logger.org.apache.catalina=DEBUG, R
log4j.logger.org.apache.catalina.core.ContainerBase.Catalina.localhost=DEBUG, R 
log4j.logger.org.apache.catalina.core=DEBUG, R 
log4j.logger.org.apache.catalina.session=DEBUG, R 
复制log4j-1.2.9.jar和commons-logging.jar到
D:\jakarta-tomcat-5.5.8\common\lib
 
20.使用windows域用户验证 

[url]http://jcifs.samba.org/src/docs/ntlmhttpauth.html[/url]
zl芊芊zl(作者)
2007-10-12 19:25
3
[url]http://blog.csdn.net/arielxp/archive/2005/03/16/321469.aspx[/url]

别人的blog借鉴一下[emot]23[/emot]
游客请输入验证码