Tomcat配置http自动跳转至https

2023-07-20 14:13:24 浏览数 (2)

1、配置web.xml(和server.xml在同一目录下),在后面一部分添加如下一段话

代码语言:javascript复制
<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端口
代码语言:javascript复制
<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设置的密码)" />

0 人点赞