• haproxy转发真实IP给web


    1.在haproxy.cfg中加入下面参数。

    option forwardfor               #如果后端服务器需要获得客户端真实ip需要配置的参数,必须要放在listen模块下 

    2.如果是apache,则加入下面参数(即修改)

    LogFormat  “”%{X-Forwarded-For}i”%l %t "%r" %>s %b "%{Referer}i""%{User-Agent}i"" combined 主要是“”%{X-Forwarded-For}i 这个参数可以记录IP

    这里我们可以写成这样方便切割日志 LogFormat  “%{X-Forwarded-For}i %l %t "%r" %>s %b "%{Referer}i""%{User-Agent}i"" combined 注意空格之类的,可以直接复制

    3.如果是后端web是nginx则加入下面参数

    set_real_ip_from ip;(这个ip填写的是proxy的ip)  

    real_ip_header X-Forwarded-For;

    log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘                 

              ‘$status $body_bytes_sent “$http_referer” ‘                 

              ‘”$http_user_agent” “$http_x_forwarded_for”‘

    =============================================  (后面日志路径也要定义main 和Apache一样,属于一种日志格式)

    在log_format里添加$remote_addr或者$http_x_forwarded_for参数。

  • 相关阅读:
    数据库各类模板
    React+Cesium安装部署
    VS2019+QT 制作自定义控件
    Vue+arcgis(1)
    将TIF/PNG等转为GeoTIFF
    QT 同名信号无法识别的问题
    VSCode配置PyQt5
    Python中类属性和self属性的区别
    postgresql的数据复制
    在windows server 2012 R2上搭建nginx环境
  • 原文地址:https://www.cnblogs.com/shiyiwen/p/5032449.html
Copyright © 2020-2023  润新知