【发布时间】:2014-09-19 10:25:45
【问题描述】:
我在 Tomcat 6.0 上部署了我的 Web 应用程序,机器的 IP 地址为 10.xx.xx.90。然后我从具有 ip 地址 (10.xx.xx.56) 的 m/c 向这个应用程序发出 http 请求(来自浏览器)。
我正在尝试使用以下代码在 servlet 过滤器中获取客户端 (10.xx.xx.56) 的 IP 地址。但我没有在标头信息中获取 remoteaddress 参数的任何值,并且 request.getRemoteAddr() 返回部署应用程序的机器的 IP 地址,即 10.xx.xx.90。两者之间没有负载均衡器或代理。
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
StringBuffer ipLog = new StringBuffer("FILTER_LOG").append(httpServletRequest.getRemoteAddr());
Enumeration<String> e = httpServletRequest.getHeaderNames();
if (e != null) {
while (e.hasMoreElements()) {
String header = e.nextElement();
ipLog.append(header).append(" - ").append(httpServletRequest.getHeader(header));
}
}
System.out.println(ipLog);
Tomcat 是否在此处阻止或更改客户端 IP 地址?如果是,那么我需要更改什么配置才能获得真实的客户端 IP 地址?
提前谢谢..
【问题讨论】:
-
@folkol "Tomcat 6.0",让我们仔细阅读问题!
-
你在后面运行Tomcat吗? Apache 还是您实际上是在配置的端口上点击 tomcat?访问日志说什么 - 你能看到那里的远程 IP 吗?
-
那么让我重新表述一下。您使用的是哪个确切版本的 Tomcat 6?我尝试在使用 Java 1.7.0_60-ea 的 Mac 上使用 Tomcat 6.0.41 记录远程 IP。这按预期工作。
-
@AndersR.Bystrup :我在配置的端口上点击 tomcat。标头信息打印为 FILTER_LOG 10.xx.xx.90content-type - text/xml; charset=UTF-8accept - text/*connection - closecache-control - no-cachepragma - no-cachehost - 10.xx.xx.90:8085content-length - 1052
-
@folkol : 我正在使用 apache-tomcat-6.0.20...我正在点击来自浏览器的请求
标签: java apache tomcat jakarta-ee servlets