tomcat配置http自动跳转至https

  • Post author:
  • Post category:其他




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设置的密码)" />



版权声明:本文为liaos666原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。