I have Spring Boot based micro-services environment setup with this configuration -
- nginx as the load balancer on centos 7. (configured to use x-forwarded-for)
- Spring boot powered API Gateway based on netflix zuul proxy server. Tomcat is embedded container.
- Products micro-service based on Spring Cloud. Tomcat as the embedded container.
Spring Boot version : 1.5.6
When end user is making call to Product Microservice, it goes through Nginx -> Api gateway -> Products Service.
Now the problem comes when i want to get the Remote Client IP Address in products Microservice. I always get 127.0.0.1 as the ip address. Here is the code in Products microservice that fetches client IP
private String getClientIP() {
String xfHeader = request.getRemoteAddr();
if (StringUtils.isBlank(xfHeader) || xfHeader.equals("127.0.0.1")) {
return request.getHeader("X-Forwarded-For");
}
return xfHeader.split(",")[0];
}
API Gateway application.properties are configured to use server.use-forward-headers: true
P.S. When i tries switching from tomcat to undertow in my api-gateway, then i start getting the real client ip address in products microservice. So problem lies somewhere in my Tomcat Configuration in API Gateway.