带有CDN的Tomcat RemoteIpValve配置

时间:2017-03-01 03:49:24

标签: java iis cdn tomcat8 x-forwarded-for

我在IIS 8后面配置了Tomcat 8.此外,我启用了CDN服务。

主机已启用RemoteIpValve

<Valve className="org.apache.catalina.valves.RemoteIpValve"         
        remoteIpHeader="x-forwarded-for" 
        proxiesHeader="x-forwarded-by" 
        protocolHeader="x-forwarded-proto"/>

日志显示为

org.apache.catalina.valves.RemoteIpValve.invoke Incoming request /api/service/dealer/getStates with originalRemoteAddr '127.0.0.1', originalRemoteHost='127.0.0.1', originalSecure='false', originalScheme='http' will be seen as newRemoteAddr='121.244.190.83', newRemoteHost='121.244.190.83', newScheme='http', newSecure='false'

访问日志配置

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="web.hyundai.co.in_access_log" suffix=".txt"
               pattern="x-forwarded-for : %{x-forwarded-for}i %h %t &quot;%r&quot; %s %b"/>

并在访问日志中

x-forwarded-for : 121.243.37.18, 121.244.190.83 127.0.0.1 [01/Mar/2017:09:02:52 +0530] "GET /api/service/dealer/getStates HTTP/1.1" 200 436

现在tomcat没有拿起实际的客户端IP 121.243.37.18,而是选择了CDN服务器IP。我无法添加CDN服务器IP作为代理,因为会有许多CDN Edge服务器。如何配置tomcat以获取正确的远程IP地址

1 个答案:

答案 0 :(得分:0)

CDN是否提供&#34; X-Real-IP&#34;头? x-forwarded-for可以是通过多个代理的IP。