流量路径
客户端
nginx1
nginx2
nginx3
后端服务
前端页面
nginx1配置
server { listen 80 ; server_name your_nginx_server.com; location / { proxy_pass http://nginx2_server_address; 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 ; }
}
nginx2配置
http { .. . real_ip_header X-Forwarded-For; set_real_ip_from nginx1的IP地址; .. . server { .. . location / { proxy_pass http://nginx3_server_address; 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 ; } } .. .
}
nginx3配置
http { .. . real_ip_header X-Forwarded-For; set_real_ip_from nginx2的IP地址; .. . server { .. . location / { add_header X-Real-IP $remote_addr ; } } .. .
}