当我们使用了nginx来转发客户端的请求以后,tomcat是无法正确获取到客户端的ip地址的,而是获取到配置了nginx的那台服务器的ip地址。因为tomcat所接收到的请求是通过nginx发出来的(nginx代替客户端发了请求)。

此时需要做如下配置。

location = /freightByIp{
            proxy_pass http://xdx8082.com;
            proxy_redirect    off;
            proxy_set_header  Host             $host;
            proxy_set_header  X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
        }

这样就可以获取到真实的ip了。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-10-26
  • 2021-04-20
  • 2022-12-23
猜你喜欢
  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2021-07-21
相关资源
相似解决方案