wang-haodong opened a new issue, #5383:
URL: https://github.com/apache/shenyu/issues/5383
### Question
When accessing through IP+port number, the real IP address obtained by the
server is that of the shenyu server
shenyu version: 2.6.0
Use http method to register, websocket to synchronize data, and divide
plug-in method.
Reproduction method:
Request server IP address: 172.17.91.11 intranet
shenyu-gateway server ip address: 172.17.90.58 intranet
Server server IP address: 172.17.90.58
How to get the real IP on the server side:
`
public static String getIpAddr(HttpServletRequest request) {
try {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 ||
(INVALID_URL.equalsIgnoreCase(ip))) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 ||
(INVALID_URL.equalsIgnoreCase(ip))) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 ||
(INVALID_URL.equalsIgnoreCase(ip))) {
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 ||
(INVALID_URL.equalsIgnoreCase(ip))) {
ip = request.getRemoteAddr();
}
if (ip != null) {
String[] ips = ip.split(",");
ip = ips[0];
}
return ip;
} catch (Exception e) {
log.info("error=>", e);
}
return null;
}`
Reproduction process:
Calling method ==> curl --location
'http://172.17.90.58:9195/user/shenyu/test01'
Expected: The server log prints ip==>172.17.91.11
Actual: The server log prints ip==>172.17.90.58
![Uploading 5122897A-D379-46DF-860A-DA58DCD2CD9C.png…]()
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]