设置NGINX,把真实IP转发过来
1 2 3 4 5 6 7 8
| location / { proxy_pass http://127.0.0.1:8008/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_redirect off; }
|
修改application.yml
1 2 3 4 5
| server: use-forward-headers: true tomcat: remote-ip-header: X-Real-IP protocol-header: X-Forwarded-Proto
|
之后在程序中获取的IP (request.getRemoteAddr()
) 就是真实的IP地址了。