apache+weblogic 获取客户IP
在apache+Weblogic整合系统中,apache会对request对象进行再包装,附加一些WLS要用的头信息。这种情况下,直接用request.getRemoteAddr()是无法取到真正的客户IP的。
apache会增加下列头信息:
X-Forwarded-For=211.161.1.239
WL-Proxy-Client-IP=211.161.1.239
所取得客户的IP需要这样:
String ip=request.getHeader("X-Forwarded-For");
if(ip == null || ip.length() == 0) {
ip=request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0) {
ip=request.getRemoteAddr();
}
if(ip == null || ip.length() == 0) {
ip=request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0) {
ip=request.getRemoteAddr();
}
或者也可通过weblogic的设置直接能过request.getRemoteAddr();取得客户的IP。
在weblogic console
domain->servers->servername->General ->Advanced Options ->
WebLogic Plug-In Enabled
Specifies whether this server uses the proprietary WL-Proxy-Client-IP header. (This is needed only when WebLogic plugins are configured.)
但是如果apache设置的是反向代理这样就不行了,因为apache不会向heaer写入WL-Proxy-Client-IP的信息。只能通过第一种方法解决。
相关推荐
Kafka 2020-09-18
Wepe0 2020-10-30
杜倩 2020-10-29
windle 2020-10-29
minerd 2020-10-28
mengzuchao 2020-10-22
Junzizhiai 2020-10-10
bxqybxqy 2020-09-30
风之沙城 2020-09-24
kingszelda 2020-09-22
大唐帝国前营 2020-08-18
yixu0 2020-08-17
TangCuYu 2020-08-15
xiaoboliu00 2020-08-15
songshijiazuaa 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
newfarhui 2020-08-03
likesyour 2020-08-01