【问题标题】:Permanently redirect from http to https in Jetty 9在 Jetty 9 中从 http 永久重定向到 https
【发布时间】:2017-03-14 11:17:02
【问题描述】:

您好,我正在尝试在码头 9 中设置从 http 到 https 的永久重定向 (301)。我在各处找到的解决方案是在我的 web.xml 中添加以下内容

    <security-constraint>
  <web-resource-collection>
   <web-resource-name>Everything</web-resource-name>
   <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
   <transport-guarantee>INTEGRAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>

这会设置 302 重定向而不是 301 重定向,这是一个大问题,有人知道我如何将其更改为 301 重定向吗?

【问题讨论】:

    标签: http redirect https jetty


    【解决方案1】:

    我认为你在运输保证方面犯了一个错误,所以你必须把它改为

    在你的WEB-INF/web.xml

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

    在码头 XML 中

    <Call name="addConnector">
       <Arg>
          <New class="org.eclipse.jetty.nio.SelectChannelConnector">
             ...
             <Set name="confidentialPort">443</Set>
          </New>
       </Arg>
    </Call>
    

    【讨论】:

    • 我没有弄错。我在运输保证中尝试了 CONFIDENTIAL 和 INTEGRAL,据我所知,两者都导致完全相同的行为。
    • 您添加了连接器吗?如果你不检查我的答案编辑。
    猜你喜欢
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 2021-10-09
    • 2017-06-23
    • 2019-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多