这里我们在生产中遇到一个问题就是。我们有的用户会登录失败。但是并不是所有的用户登录失败(这里是能够正常访问网站)

所以这里想分析哪些用户登录失败,所以我们要记录他们这些登录失败的IP地址

这里我们的结构是这样的,前端的代理用的是haproxy

后端的是java 程序

所以我们要在ha里配置,让后端能够取到用户的真实IP地址

所以我们的配置就是

option                  http-server-close
    option                  forwardfor

后端的代码里去head头里的X-Forwarded-For字段

参考链接是https://gist.github.com/PiBa-NL/d826e0d6b35bbe4a5fc3

To send the ip addres of the client/webbrowser to the server/webserver behind it there are a few options:
 1- option forwardfor
 2- send-proxy
 3- source 0.0.0.0 usesrc clientip

1- option forwardfor
This is an easy option to configure in haproxy, it does require that http layer7 processing is used 'mode http' and the webserver/ webapplication that wants to log or use the ip of the client must use the http-header 'X-Forwarded-For' to read the clientip.

2- send-proxy / send-proxy-v2 / send-proxy-*
This is can be used both with mode tcp and http, it does however require that the server also understands the proxyprotocol. Some applications have added support for this protocol which adds a few bytes with ip information before the actual request.

3- source 0.0.0.0 usesrc clientip
This allows any application and any protocol to be used and see the actual client ip as the origin from the incomming connection.
It does however require to configure IPTABLES or IPFW or other firewall rules to capture reply-traffic, also the haproxy machine must be the defaultroute for the return traffic from the (web-)server.

参考文档是:

https://www.haproxy.com/doc/aloha/7.0/haproxy/http_rewriting.html#add-a-header-to-the-request

haproxy 让后端服务器记录用户的真是IP地址(记录在header头里)的更多相关文章

  1. F5中源地址转换(AutoMap)模式下后端服务器获取客户端真正的IP地址

    F5中开启AutoMap,并传递X-Forwarded-For值 开启F5源地址转换"Auto Map" 方式一: 在http profile中开启X-Forwarded-For ...

  2. nginx做反向代理负载均衡 Java怎么获取后端服务器获取用户IP

    nginx做反向负载均衡,后端服务器获取真实客户端ip   首先,在前端nginx上需要做如下配置: location / proxy_set_hearder host                 ...

  3. --with-http_realip_module选项(后台Nginx服务器记录原始客户端的IP地址 )

    转自:http://blog.itpub.net/27043155/viewspace-734234/ 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如,X-Real-IP 或 X-For ...

  4. TFS应用层服务器获取F5用户的真实IP地址(高可用性)

    当用户数量达到一定级别(例如2千)以上,为保证TFS系统的持续服务,最大程度减少因系统宕机对研发团队的影响,系统管理员一般会考虑应用层和数据库层的高可用性方案. 在应用层的高可用性方案中,目前比较常见 ...

  5. 【Go】获取用户真实的ip地址

    原文链接:https://blog.thinkeridea.com/201903/go/get_client_ip.html 用户请求到达提供服务的服务器中间有很多的环节,导致服务获取用户真实的 ip ...

  6. 获得用户的真实IP地址

    /** * 获得用户的真实IP地址 * * @access public * @return string */if (!function_exists('get_real_ip')){ functi ...

  7. PHP获取用户的真实IP地址

    本文出至:新太潮流网络博客 PHP获取用户的真实IP地址,非代理IP function getClientIP(){ global $ip; if(getenv("HTTP_CLIENT_I ...

  8. PHP获得用户的真实IP地址

    <?php /** * 获得用户的真实IP地址 * * @access public * @return string */ function real_ip() { static $reali ...

  9. js记录用户在网站的浏览记录和停留时间

    by weber开发者 from http://weber.pub/ 本文地址: http://weber.pub/js记录用户行为浏览记录和停留时间/163.html 问题 公司想统计一个用户从进入 ...

随机推荐

  1. Python学习笔记八:ORM框架SQLAlchemy

    一:SQLAlchemy使用 1:实体类的创建 ORM中的实体类与一般的Python类不同,在其中,使用 __tablename__=""指明该类与数据库中某个表相对应,然后定义一 ...

  2. Hibernate学习笔记五:反向工程快速开发

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6768513.html  一:反向工程 Myeclipse提供由 数据库表 生成 java pojo 和 hib ...

  3. Android开发之将拍摄的图片传至服务器

    package com.example.oldtab; import java.io.ByteArrayOutputStream; import java.io.File; import java.i ...

  4. Spring Cloud Dalston.SR5 BUG一记

    使用Dalston.SR5版本的Zuul时, 发现Ribbon重试不能切换服务实例, 换成Edgware.SR3,同样的配置可以切换实例进行重试 还有个不升级所有Spring Cloud组件的方法,仅 ...

  5. Centos安装Oracle数据库文本记录

    题记,本文旨在记录图形化安装过程,的过程...仅仅是回忆性学习... oracle账号登陆图形界面    #没有图形化,图形检查不通过 运行终端 Terminal cd /u01/database . ...

  6. 加了moment.js和中文语言包,那么其它时间控件的中文包就可以不引用

    <script src="//cdn.bootcss.com/moment.js/2.13.0/moment.min.js"></script> <s ...

  7. Easyui + asp.net MVC 系列教程 第19-23 节 完成注销 登录限制过滤 添加用户

    前面视频 文章地址 Easyui + asp.net MVC 系列教程 第09-17 节 完成登录 高清录制  Easyui + asp.net mvc + sqlite 开发教程(录屏)适合入门  ...

  8. java struts2入门学习---自定义类型转换

    自定义类型转换器的作用就是将struts无法识别的类型转换成自己所需要的. 比如输入:广东-东莞-虎门,对应的输出时能输出:广东省 东莞市 虎门(镇/区) 这里涉及到的知识点即是将String转换为任 ...

  9. JavaScript escape() unescape() decodeURI()函数对字符串进行编码解码

    定义和用法 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法 escape(string) 参数 描述 string 必需.要被转义或编码的字符串. 返回值 已 ...

  10. 在Linux下安装RabbitMQ

    Installing on RPM-based Linux (CentOS, Fedora, OpenSuse, RedHat) 安装新版本的RabbitMQ出错: centos端口转发神器:soca ...