在Tomcat的server.xml中将HTTP重定向到HTTPS不起作用

问题描述

我安装了tomcat 9.0.37,并且已经配置了TLS。在我的server.xml中,有以下连接器:

  <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

     
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxThreads="150" SSLEnabled="true">
    <SSLHostConfig>
            <Certificate certificateKeystoreFile="/root/.keystore"
                     type="RSA" keystorePass="changeit" />
    </SSLHostConfig>
</Connector>

如果我访问https:// localhost:8443 /时,我的连接已经安全,那么第二个连接器将按预期工作。 但是,如果我呼叫http:// localhost:8080 /,第一个连接器不会重定向我,相反,我得到的是不安全的网站。
如果我呼叫http:// localhost:8443 /(http不带tls),则会收到以下响应

Bad Request
This combination of host and port requires TLS.

我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)