Tomcat的web服务自动跳转到https的设定

来源:互联网 发布:计量型数据什么? 编辑:程序博客网 时间:2024/06/03 23:49

在web应用的web.xml中添加如下配置信息

    <security-constraint>      <web-resource-collection>        <web-resource-name>Automatic SSL Forwarding</web-resource-name>        <url-pattern>/*</url-pattern>      </web-resource-collection>      <user-data-constraint>        <transport-guarantee>          CONFIDENTIAL        </transport-guarantee>      </user-data-constraint>    </security-constraint>

配置Tomcat

  • 制作证书
    "%JAVA_HOME%\bin\keytool" -genkey -alias tomcat -keyalg RSA
    -keystore \path\to\my\keystore

    参考:https://tomcat.apache.org/tomcat-9.0-doc/ssl-howto.html#Prepare_the_Certificate_Keystore

  • 配置SSL,在tomcat的配置文件server.xml中配置如下信息

    <Connector acceptCount="100" connectionTimeout="20000"        disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192"        maxSpareThreads="75" maxThreads="150" minSpareThreads="25" port="80"        redirectPort="8443" />    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" acceptCount="100" clientAuth="false"        disableUploadTimeout="true" enableLookups="false" maxThreads="150"        scheme="https" secure="true" sslProtocol="TLS"         keystoreFile="C:/Users/SHOU/.keystore" keystorePass="test1234"    />

如果想要去掉地址中的端口号8443 。讲上述tomcat配置信息中的端口号都修改为 443 即可

配置参考

0 0
原创粉丝点击