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

所以这里想分析哪些用户登录失败,所以我们要记录他们这些登录失败的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. ReactNative踩坑日志——使用async/await语法解决网络请求的异步导致的指令执行顺序错乱问题

    转载请注明原文地址: ReactNative的fetch是天然的异步请求,因此,如果你在一个代码块中使用了fetch,那么在执行的时候程序不会等待网络响应结束才执行下一条代码,而是会直接按顺序执行完整 ...

  2. Linux内存分配机制之伙伴系统和SLAB

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6539590.html  内核内存管理的一项重要工作就是如何在频繁申请释放内存的情况下,避免碎片的产生.这就要求 ...

  3. requestsManager:didFailRequest:withError: Error Domain=com.albertodebortoli.goldraccoon Code=-1000 "(null)" UserInfo={message=Unknown error!}

    场景:最近IOS开发中需要用到FTP上传,最初是用GoldRaccoon 看后台FTPServer日志,一直都是disconnected.自己对FTP也是懂些皮毛,所以只剩下一坑的无奈.FTP服务器是 ...

  4. 通过Navicat Premium迁移Oracle到EDB迁移实战

    1.1 DB migration analysis   在从Oracle向EDB迁移数据之前,须要做非常多准备工作.比方须要分析源数据库数据量大小.数据是否稳定.异构数据库兼容.编码方式.业务逻辑(存 ...

  5. excel如何快速更改表格边框的颜色

    1.当完成基本的表格设置之后,对颜色不甚满意,怎么办 2.重新给表格选择一种颜色,这里会出现一个“笔”形状的鼠标箭头,不用理睬她 3.再次给表格统一加边框即可(开始--边框--所有框线)

  6. WinHttp编写HTTP服务器示例代码

    这是微软提供的示例程序,原文地址在此https://msdn.microsoft.com/en-us/library/windows/desktop/aa364640(v=vs.85).aspx HT ...

  7. Ubuntu18.04中配置QT5.11开发环境

    准备工作 参考 https://wiki.qt.io/Install_Qt_5_on_Ubuntu . # 安装g++ sudo apt install build-essential # sudo ...

  8. js截取相应的域名----正则匹配法 和校验Url 正则表达式

    js截取相应的域名----正则匹配法 和校验Url 正则表达式 用javascript截取相应的域名方法两种,供大家参考 1.方法1: [javascript] view plain copy fun ...

  9. linux中DHCP服务配置文件/etc/dhcpd.conf详细说明

    DHCP服务的配置 dhcpd.conf 是DHCP服务的配置文件,DHCP服务所有参数都是通过修改dhcpd.conf 文件来实现,安装后dhcpd.conf 是没有做任何配置的,将/usr/sha ...

  10. Centos7-Lvs+Keepalived架构

      Centos7-Lvs+Keepalived架构 LVS+Keepalived 介绍 1 .   LVS LVS 是一个开源的软件,可以实现 LINUX 平台下的简单负载均衡. LVS 是 Lin ...