我在我的Web应用程序中配置了SSL . 我已根据所需步骤在我的Tomcat中安装了证书 .
我一直关注的教程是https://www.mulesoft.com/tcat/tomcat-security
我已强制使用https over http,这意味着对http的任何请求都将转发到https . 我在server.xml中进行了以下更改
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443"
proxyHost="10.1.1.1" proxyPort="80"
URIEncoding="UTF-8"
maxHttpHeaderSize="32768"/>
web.xml更改如下:
<security-constraint>
<web-resource-collection>
<web-resource-name>SecureConnection</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
但是,正在发生的重定向是临时重定向,即302.我想使用301重定向,即永久重定向 .
我怎样才能做到这一点?
1 回答
这是在您的Realm上配置的 . 请参阅特定Realm实现的
transportGuaranteeRedirectStatus
属性 .https://tomcat.apache.org/tomcat-8.5-doc/config/realm.html
例如:server.xml具有开箱即用的功能
它没有设置
transportGuaranteeRedirectStatus
所以它默认为302.如果你想让它使用301,只需将属性transportGuaranteeRedirectStatus="301"
添加到顶级Realm(你可能没有嵌套的Realms,具体取决于你的配置)并重启Tomcat .例如:
如果您的配置中未定义Realm标记,则Tomcat将默认使用NullRealm . 如果要在这种情况下覆盖重定向,则只需要在其下面设置
transportGuaranteeRedirectStatus
属性来定义NullRealm .希望有所帮助!