tomcat 配置域名和ssl证书

在tomcat上配置域名和ssl证书,记录一下;

环境:

阿里云ECS CentOS 6.9

GeoTrust DV 证书

tomcat 7.0.92

 

1、在阿里云 域名解析 控制台,配置域名DNS解析;

比如:二级域名为  test.com

主机记录:www       ( 即为 www.test.com )

记录值:绑定的IPV4地址

其他默认;

2、在阿里云 SSL证书 控制台,下载证书文件,tomcat下包含pfx文件、秘钥pfx-password.txt文件;

服务器类型选择Tomcat,点击下载,压缩包中包含 xxxxx__test.com.pfx, pfx-password.txt;

3、在tomcat根目录,创建cert目录,存放以上下载的两个文件

比如:./cert/test.com.pfx

          ./cert/pfx-password.txt

4、在./cert/web.xml文件中,web-app节点,添加如下内容:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>SSL</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

5、在./cert/server.xml文件中

5.1、80端口需要备案,可以使用http 8099端口先做测试;

在Service节点,添加如下内容,访问 http 8099端口,会自动跳转到 https 443 端口

                                         比如:http://www.test.com:8099   =》  https://www.test.com

    <Connector port="8099" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443" />

5.2、配置SSL证书和域名

在Service节点,添加如下内容,

    <Connector port="443"  
          protocol="org.apache.coyote.http11.Http11Protocol"  
          SSLEnabled="true"  
          scheme="https"  
          secure="true"  
          keystoreFile="cert/test.com.pfx"  
          keystoreType="PKCS12"  
          keystorePass="xxxxxxxx"           ==》pfx-password.txt文件中的秘钥
          clientAuth="false"  
          SSLProtocol="TLSv1+TLSv1.1+TLSv1.2"  
          ciphers="TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256" /> 

 

修改如下内容:

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="443" />

 

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="www.test.com">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI resources under the key "UserDatabase".  

              Any edits that are performed against this UserDatabase are immediately available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>

      <Host name="www.test.com"  appBase="webapps" unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>

 

配置结束,启动tomcat服务;

测试地址:https://www.test.com
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值