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
    

Tomcat是一个开源的Web服务器,用于部署Java应用程序。要在Tomcat 6.0中配置SSL以支持HTTPS连接,需要进行以下步骤: 1. 生成密钥库(keystore)和自签名证书:可以使用Java自带的keytool工具生成密钥库和证书。打开命令行工具,执行以下命令: ```bash keytool -genkey -alias tomcat -keyalg RSA -keystore /path/to/yourkeystore ``` 按照提示输入组织信息和密码,完成后会在指定路径生成一个名为`yourkeystore`的密钥库文件。 2. 配置Tomcat服务器以使用SSL: a. 找到Tomcat配置文件`server.xml`,通常位于`conf`目录下。 b. 在该文件中找到`<Connector>`元素,用于定义HTTP连接器。 c. 复制该`<Connector>`元素,并修改为SSL连接器,指定密钥库文件的路径和密码,示例如下: ```xml <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" scheme="https" secure="true" SSLEnabled="true" keystoreFile="/path/to/yourkeystore" keystorePass="yourpassword" clientAuth="false" sslProtocol="TLS"/> ``` 请确保将`keystoreFile`和`keystorePass`属性的值替换为你的密钥库文件路径和密码。 3. 配置域名: a. 将你的域名DNS解析记录指向托管Tomcat服务器的IP地址。 b. 在Tomcat配置虚拟主机(如果需要),可以添加一个新的`<Host>`元素到`server.xml`中,指定域名,并将SSL连接器的`proxyName`和`proxyPort`属性设置为域名和443端口,如下所示: ```xml <Host name="yourdomain.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="ROOT" /> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" scheme="https" secure="true" SSLEnabled="true" keystoreFile="/path/to/yourkeystore" keystorePass="yourpassword" clientAuth="false" sslProtocol="TLS"/> </Host> ``` 注意,如果你想要Tomcat直接监听80端口而非使用8080,你需要在`<Connector>`中进行相应的配置,但通常80端口需要管理员权限。 完成以上配置后,重启Tomcat服务器使设置生效。用户通过HTTPS协议和配置域名访问你的Web应用时,浏览器会显示安全锁标示,表示连接是加密的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值