nginx在varnish后端做负载均衡,后端tomca获取客户端真实IP


nginx在varnish后端做负载均衡,后端tomca获取客户端真实IP


1.设置nginx配置文件

   首先要确定nginx做负载均衡,在安装时把http_realip_module 安装上了。

   查看方法: /usr/local/nginx/sbin/nginx -V

  配置nginx.conf

   vim /usr/local/nginx/conf/nginx.conf

  加入 set_real_ip_from 192.168.88.131;   

  重新加载nginx: /usr/local/nginx/sbin/nginx reload


2.设置varnish配置文件

   vim /usr/local/varnish/etc/varnish/default.vcl

  加入如下配置:

 sub vcl_recv {

remove req.http.X-real-ip;

set req.http.X-real-ip = client.ip;

set req.http.X-Forwarded-For = client.ip;

  }


启动varnish:

/usr/local/varnish/sbin/varnishd -f /usr/local/varnish/etc/varnish/default.vcl -s file,/home/varnish_cace,1G -T 127.0.0.1:2000 -a 0.0.0.0:80


现在从后端的tomcat上获取客户端真实的IP地址了。。

你可能感兴趣的:(tomcat,nginx,varnish)