haproxy+nginx相关的配置

haproxy tcp模式 + nginx http模式 ,nginx打印客户端源IP

haproxy 增加 send-proxy参数,用于启用代理协议(Proxy Protocol)支持

listen nginx-web
    bind 0.0.0.0:80
    mode tcp
    option tcplog
    balance roundrobin
    server nginx-1 server1:81 check inter 10000 fall 2 rise 2 weight 1 send-proxy
    server nginx-2 server2:81 check inter 10000 fall 2 rise 2 weight 1 send-proxy
    server nginx-3 server3:81 check inter 10000 fall 2 rise 2 weight 1 send-proxy

nginx http模块,增加打印$proxy_protocol_addr变量,即代理协议传递的客户端IP地址

复制代码
http {

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''   close;
    }
    log_format  main  '$proxy_protocol_addr - $remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
复制代码

nginx server模块,增加proxy_protocol配置,并启用了Proxy Protocol支持,这意味着它预期从HAProxy那里接收使用Proxy Protocol传递的请求。此配置确保Nginx可以正确地识别代理的客户端IP地址。

server {
    listen     81 default_server proxy_protocol;

 

posted @   szcj~  阅读(108)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示