配置tomcat7的https证书


配置pfx证书

server.xml

     "8443"
               protocol="org.apache.coyote.http11.Http11Protocol" 
               SSLEnabled="true" 
               enablelookups="false" 
               disableUploadTimeout="true"
               acceptCunt="100" 
               maxhttpHeaderSize="8192" 
               minSpareThreads="25"
               maxThreads="150" 
               scheme="https" 
               secure="true"
               clientAuth="false" 
               sslProtocol="TLS" 
               keystoreType="PKCS12"
               keystoreFile="cert\zhengshu.pfx"
               keystorePass="123456"
               />

注意:对于启用APR情况下protocol不能使用HTTP/1.1,否则会报异常:java.lang.Exception: Connector attribute SSLCertificateFile must be defined when  using SSL with APR。

keystoreFile为证书路径,在tomcat_home目录下可以直接写cert/zhengshu.pfx,如:/tomcat/cert/zhengshu.pfx

http自动转https访问

web.xml

在welcome-file-list节点后添加以下

    <login-config>  
          
        <auth-method>CLIENT-CERTauth-method>  
        <realm-name>Client Cert Users-only Arearealm-name>  
    login-config>  
    <security-constraint>  
          
        <web-resource-collection >  
            
            <web-resource-name>SSLweb-resource-name>
            <url-pattern>/*url-pattern>  
        web-resource-collection>  
        <user-data-constraint>  
            <transport-guarantee>CONFIDENTIALtransport-guarantee>  
        user-data-constraint>  
    security-constraint>