Proxy Server Configuration

在使用代理服务器时,确保已正确配置应用程序非常重要。例如,许多应用程序将有一个负载均衡器,该负载均衡器通过将请求转发到 [role="bare"][role="bare"]https://example.com/ 处的应用程序服务器来响应对 [role="bare"][role="bare"]https://192.168.1:8080 的请求。如果没有正确的配置,应用程序服务器将不知道负载均衡器存在,并将把请求视为 [role="bare"][role="bare"]https://192.168.1:8080 是由客户端请求的。

When using a proxy server it is important to ensure that you have configured your application properly. For example, many applications will have a load balancer that responds to request for [role="bare"]https://example.com/ by forwarding the request to an application server at [role="bare"]https://192.168.1:8080 Without proper configuration, the application server will not know that the load balancer exists and treat the request as though [role="bare"]https://192.168.1:8080 was requested by the client.

要解决此问题,可以使用 RFC 7239 来指定正在使用负载均衡器。为了让应用程序意识到这一点,你需要配置应用程序服务器,使其了解 X-Forwarded 头。例如,Tomcat 使用 RemoteIpValve,Jetty 使用 ForwardedRequestCustomizer。此外,Spring 4.3+ 用户可以利用 ForwardedHeaderFilter

To fix this you can use RFC 7239 to specify that a load balancer is being used. To make the application aware of this, you need to either configure your application server aware of the X-Forwarded headers. For example Tomcat uses the RemoteIpValve and Jetty uses ForwardedRequestCustomizer. Alternatively, Spring 4.3+ users can leverage ForwardedHeaderFilter.

Spring Boot 用户可以使用 server.use-forward-headers 属性来配置应用程序。有关详细信息,请参阅 Spring Boot documentation

Spring Boot users may use the server.use-forward-headers property to configure the application. See the Spring Boot documentation for further details.