tomcat配置http自动跳转至https

本文详细介绍了如何在web.xml中配置安全约束以启用SSL,并在server.xml中设置HTTP到HTTPS的自动重定向,确保网站数据传输的安全。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、配置web.xml(和server.xml在同一目录下),在后面一部分添加如下一段话
<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>

配置后效果如下:
在这里插入图片描述

2、配置server.xml 即通过redirect实现http 8090端口自动跳转至https 8095端口
<Connector port="8090" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8095" URIEncoding="UTF-8"/>
<Connector port="8095" protocol="org.apache.coyote.http11.Http11NioProtocol"
				maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
				clientAuth="false"
				URIEncoding="UTF-8"
				sslEnabledProtocols="SSLv2,SSLv3,TLSv1,TLSv1.1,TLSv1.2,SSLv2Hello"
				keystoreFile="/app/wheelchair/ssl/server.keystore" keystorePass="passwd(keystore设置的密码)" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值