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

所以这里想分析哪些用户登录失败,所以我们要记录他们这些登录失败的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. 算法笔记_226:填符号凑算式(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 匪警请拨110,即使手机欠费也可拨通! 为了保障社会秩序,保护人民群众生命财产安全,警察叔叔需要与罪犯斗智斗勇,因而需要经常性地进行体力训练和智力训 ...

  2. 行内元素有哪些?块级元素有哪些? 空(void)元素有那些?

    行内元素:a.b.span.img.input.strong.select.label.em.button.textarea块级元素:div.ul.li.dl.dt.dd.p.h1-h6.blockq ...

  3. Shell编程初步

      一:Hello World 新建一个文件,命名时以 .sh 为后缀.每个bash文件开头第一行表名文件类型: #!/bin/bash 然后在下面输入代码. 比如输出hello world: #!/ ...

  4. mybatis中模糊查询的使用以及一些细节问题的注意事项

    页面有个功能 为 根据 品牌名进行 关键字查询,对应到数据库的是brand表的name字段的模糊查询 如果用的是SSM框架,在mybatis中我们需要自己写sql语句,涉及到like的模糊查询,myb ...

  5. 转 php 5.3.6中php-fpm 配置

    php 5.3.6 中 php-fpm 配置 成 服务启动 从php5.3.3开始 源码中开始包含 php-fpm,不用专门再打补丁了,只需要解开源码直接configure, 关于php-fpm的编译 ...

  6. 不同类型的磁盘存储在Ubuntu下的性能测试

    Ubuntu下通过lsusb判断USB存储是否是USB3.0: # 要查看Seagate这个移动硬盘 lsusb 或者 lsusb -t $ lsusb Bus Device : ID : Intel ...

  7. hql语句的case when then else end问题

    http://www.iteye.com/problems/4499 hibernate count不支持case when?

  8. 事务的四个属性ACID

    事务四大特征:原子性,一致性,隔离性和持久性. 1. 原子性(Atomicity) 一个原子事务要么完整执行,要么干脆不执行.这意味着,工作单元中的每项任务都必须正确执行.如果有任一任务执行失败,则整 ...

  9. linux线程学习

    按照书上写的,不知道为什么有问题: //已解决,参考最新的blog,哈哈 #include <stdlib.h> #include <pthread.h> #include & ...

  10. CMFCPropertyGridProperty用法

    MFCPropertyGridCtrl 是VC 2008 pack中的控件类. CMFCPropertyGridProperty这个控件类中的属性值类类. 针对修改属性后,对属性值改变的消息处理: 方 ...