linux下利用tcpdump抓包工具排查nginx获取客户端真实IP实例

一、nginx后端负载服务器的API在获取客户端IP时始终只能获取nginx的代理服务器IP,排查nginx配置如下

upstream sms-resp {
         server 192.168.5.216:8501;
         server 192.168.5.217:8501;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass  http://sms-resp;
            proxy_set_header host $host;
            proxy_set_header X-real-ip $remote_addr;
            proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
        }

nginx配置项已经配置了转换真实客户端IP的参数设置,那么需要抓包来看看是否是真正的转换了客户端IP。

二、安装tcpdump抓包工具

在nginx和后端API服务器上分别安装tcpdump

[root@push-5-216 ~]# yum install -y tcpdump

三、使用tcpdump抓包

我在172.28.146.109上浏览器调用172.28.5.215的nginx代理的HTTP接口,nginx将请求分发到192.168.5.216上,这里nginx和后端API是走的192.168网段。

首先抓取从172.28.146.109到172.28.5.215,80端口的TCP包

猜你喜欢

转载自www.cnblogs.com/sky-cheng/p/11058221.html