我在 Ubuntu 上配置 Tomcat 9 时遇到问题。我在 Tomcat 下部署了 1 个应用程序。创建 SSL 并将 HTTP 重定向到 HTTPS。例如我的应用程序名称 - 示例:) 所以我有这个:
我的 server.xml 配置文件的一部分:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="60000"
redirectPort="443"
enableLookups="false"
useBodyEncodingForURI="true"/>
<Connector port="443" protocol="HTTP/1.1"
maxThreads="150"
SSLEnabled="true"
scheme="https"
secure="true"
clientAuth="false"
sslProtocol="TLS"
keystoreFile="path to cert"
keystoreType="PKCS12"
keystorePass="cert password"/>
在 web.xml 的 EOF 中,我有:
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Context</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
重定向工作正常,当我输入http://localhost时,我会自动重定向到 HTTPS,但前提是我输入http://localhost。当我输入http://localhost/example - 重定向不起作用,为什么?
所以,我在 webapps/ROOT 中添加 index.jsp:
<%
String redirectURL = "/example";
response.sendRedirect(redirectURL);
%>
重定向工作正常
所以,我想将“示例”永久重定向到根目录,所以我添加到我的 server.xml 内容中:
<Context path="" docBase="example" debug="0" reloadable="true"></Context>
重定向工作正常,当我输入http://localhost我看到示例内容。但是有一个问题 - HTTP - 添加“上下文”后,HTTPS 重定向不起作用。为什么?用了半天的Tomcat配置,不知道为什么添加上下文后重定向不起作用。