Spring Redirect 命令重定向到 Load Balancer 下的 Localhost

标签 spring tomcat amazon-web-services load-balancing

我有一个使用 Spring MVC 构建的 Java Web 应用程序,它在 Tomcat 上运行,代理 Apache Httpd 在 AWS 的 EC2 实例上运行,并使用 SSL 配置负载均衡器。

请求

https://some_domain/first_uri

首先转到负载均衡器,负载均衡器将连接重定向到 Apache 为(https 到 http,因为为负载均衡器配置了 SSL)

http://some_domain/first_uri

Apache 重定向到本地主机 (Tomcat)。

当“/first_uri”的 Controller 进行像

这样的重定向时

redirect:https://sub.some_domain/some_uri

我在浏览器中看到的结果是

https://localhost/first_uri

我只是想不通我必须在这里配置什么,配置 Spring?配置 Apache HTTPD 或负载均衡器?

如果有人遇到同样的问题,请帮忙。

不是:还使用 Spring Security。

Not2:我只是在没有 SSL 的情况下尝试(使用 http),同样的事情发生了,我认为这与 https 的使用无关。

更新:这个问题可能只发生在我尝试重定向到子域的地方

最佳答案

以下对我有用:

在 tomcat server.xml 中: (主要在/opt/tomcat/conf/server.xml)

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443"
            proxyName="localhost"
            proxyPort="443"
            scheme="https"/>

这里的 proxyName 是“localhost”。 将 proxyName 更改为您所需的域。

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443"
            proxyName="mydomain.com"
            proxyPort="443"
            scheme="https"/>

引用:http://tomcat.apache.org/tomcat-7.0-doc/config/http.html#Proxy_Support

关于Spring Redirect 命令重定向到 Load Balancer 下的 Localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38508765/

相关文章:

Spring boot 和 Spring Actuator - 禁用安全性

java - 使用 @Value 获取一个 int 值

java - Java webapp 中的病毒扫描?

tomcat - 增加 Tomcat 服务器启动时间

tomcat - t 找到基本名称 org.eclipse.persistence.exceptions.i18n.PersistenceUnitLoadingExceptionResource 的包,语言环境 en_US

amazon-web-services - aws s3 ls 过滤器存储类(标准)

spring - 如何使用@JmsListener 获取转换后的对象

java - 在 spring-boot 项目中使用 spring mvc xml 项目

hadoop - 独立处理大量小文件

amazon-web-services - S3 put()事件lambda触发器中可以包含多少条记录?