我在tomcat上有一个Web应用程序 http://localhost:8080/WebApp/
我已经配置了Apache 2(mod_proy),因此localhost可以直接访问Web应用程序,并输出端口和名称:例如 http://localhost
<VirtualHost localhost:80>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/WebApp/
ProxyPassReverse / http://localhost:8080/WebApp/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
index.html正确显示http://localhost.但是如果servlet重定向:
@WebServlet(description = "...", urlPatterns = { "/login" })
public class LoginServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException
{
response.sendRedirect("a.html");
}
}
Run Code Online (Sandbox Code Playgroud)
我使用URL http://localhost/login- 我被重定向到http://localhost/WebApp/a.html
如何获得正确的重定向http://localhost/a.html?
当前,我们在运行Grails的Tomcat实例之前使用AWS ELB-> Apache。我们使用Apache将http请求重定向到https请求。在我们的常规网站上,这对我们来说很好。尝试将我们的网站嵌入到Chrome的iframe中时,问题就来了。Chrome浏览器不喜欢将https网站重定向到http页面(即使该页面随后随后重定向到https)。发生这种情况的原因是,对于Spring Security,它看起来像在http上,因为我们在负载均衡器后面。这是来自Developer Tools的网络乒乓球:

将同一页面放在Chrome上的iframe中时,就会出现问题。

我们发现了许多解决方案,这些解决方案将允许Spring Security Grails插件针对某些URL模式将http请求重定向到https请求。 这里和这里是其中两个示例。我们已经通过让Apache拦截http请求并重定向到https来解决了这个问题。
问题是Chrome甚至不会在iframe中发出http请求。我们需要能够告诉Spring Security,即使您收到的已保存请求正在使用http,也需要在完成身份验证后将其更改为https。
我们认为可能可行的一种解决方案是使用contextRelative而不是绝对URL更改为相对URL,由于ELB代理,Spring Security将其视为http。这篇文章似乎暗示了相同的观点,但是该解决方案也没有更改将contextRelative更改为“ true”时生成的URL。
我们如何才能告诉Grails Spring Security插件始终将URL设置为相对URL或将其强制为https方案,以便我们可以在Chrome的iframe中运行该应用程序?