记录使用Nginx做代理后,spring boot 日志获取真实IP

设置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

猜你喜欢

转载自blog.csdn.net/chen846262292/article/details/84974851