如下图所示,客户端通过Nginx Proxy1 和 Nginx Proxy2 两层反向代理才访问到具体服务Nginx Backend(或如Tomcat服务)。那Nginx Backend如何才能拿到真实客户端IP呢?
接下来我们来看看如何才能获取到客户端真实IP。
场景1
场景1是很简单的场景,Nginx Proxy直接把请求往后转发,没有做任何处理。
Nginx Proxy
192.168.107.107 nginx.conf
location /test {
proxy_pass http://192.168.107.112:8080;
}
192.168.107.112 nginx.conf
location /test {
proxy_pass http://192.168.107.114:8080;
}
Nginx Proxy就是简单的把请求往后转发。
Nginx Backend
192.168.107.114 nginx.conf
location /test {
default_type text/html;
charset gbk;