设置NGINX,把真实IP转发过来
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;
}
配置spring boot中内嵌的tomcat,使用header中的IP (application配置文件)
server.use-forward-headers = true
server.tomcat.remote-ip-header = X-Real-IP
server.tomcat.protocol-header = X-Forwarded-Proto
转至 https://github.com/gexiangdong