当前位置: 代码迷 >> 综合 >> tomcat配置http转https
  详细解决方案

tomcat配置http转https

热度:51   发布时间:2023-09-27 11:17:14.0


1. 开启https默认端口443

<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile : "证书路径"
keystorePass : "证书密码"

2. 开启http默认端口80, 这里的redirectPort设置为443

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

3. 配置8009端口重定向为443

<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />

4. 在项目文件web.xml中的</web-app>加入以下配置,强制SSL访问

<!-- 强制SSL配置,即普通的请求也会重定向为SSL请求 -->
   <security-constraint>
        <web-resource-collection>
            <web-resource-name>SSL</web-resource-name>
            <url-pattern>/*</url-pattern> 全站使用SSL
        </web-resource-collection>
        <user-data-constraint>
            <description>SSL required</description>
            CONFIDENTIAL: 要保证服务器和客户端之间传输的数据不能够被修改,且不能被第三方查看到
            INTEGRAL: 要保证服务器和client之间传输的数据不能够被修改
            NONE: 指示容器必须能够在任一的连接上提供数据。(即用HTTP或HTTPS,由客户端来决定)
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <!-- <security-constraint>
    <web-resource-collection>
    <web-resource-name>OPENSSL</web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
<user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint> -->
  相关解决方案