Spring Boot Proxy

获取Nginx转发请求的Client IP

  1. Nginx配置转发
1
2
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  1. Zuul获取Real IP
1
2
3
val split = request.getHeader("X-Forwarded-For").split(",")
val realIP = split[0]
val dockerIP = split[1]

获取非转发情况下的Client IP

  1. REMOTE_ADDR - This contains the real IP address of the client. That is the most reliable value you can find from the user.

  2. REMOTE_HOST - This will fetch the Host name from which the user is viewing the current page. But for this script to work, Hostname Lookups On inside httpd.conf must be configured.