【问题标题】:Tomcat 9 context docBase redirect to httpsTomcat 9 上下文 docBase 重定向到 https
【发布时间】:2018-06-24 06:19:36
【问题描述】:

我在 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配置,不知道为什么添加上下文后重定向不起作用。

【问题讨论】:

    标签: tomcat redirect https tomcat9 docbase


    【解决方案1】:

    尝试调用您的应用程序 ROOT。这对我有用:)

    【讨论】:

      猜你喜欢
      • 2021-09-11
      • 2015-04-05
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 2015-02-16
      相关资源
      最近更新 更多