nginx 代理和负载均衡

Configuring NGINX to accept the PROXY Protocol
nginx作为tcp负载均衡

http {
    log_format combined '$proxy_protocol_addr - $remote_user [$time_local] '
                        '"$request" $status $body_bytes_sent '
                        '"$http_referer" "$http_user_agent"';
    ...

    server {
        server_name localhost;

        listen 80   proxy_protocol;
        listen 443  ssl proxy_protocol;

        ssl_certificate      /etc/nginx/ssl/public.example.com.pem;
        ssl_certificate_key  /etc/nginx/ssl/public.example.com.key;

        set_real_ip_from 192.168.1.0/24;
        real_ip_header   proxy_protocol;

        location /app/ {
            proxy_pass       http://backend1;
            proxy_set_header Host            $host;
            proxy_set_header X-Real-IP       $proxy_protocol_addr;
            proxy_set_header X-Forwarded-For $proxy_protocol_addr;
        }
    }
} 

stream {
...
    server {
        listen         12345;
        proxy_pass     example.com:12345;
        proxy_protocol on;
    }

}
  1. 接受tcp proxy代理流量
    该示例假设在NGINX前面有一个负载均衡器,例如Amazon ELB,它平衡所有传入的HTTPS流量
    NGINX接受端口443上的HTTPS流量(listen 443 ssl;),和80端口的流量
    并通过PROXY协议(proxy_protocol参数)接受从负载平衡器传递的客户端的IP地址。负载均衡器地址在set_real_ip_from指令中指定。客户端的IP地址通过proxy_protocol参数从real_ip_header指令传递
    具体代码在:ngx_proxy_protocol_read 中解析proxy协议得到客户端的IP地址
  2. 作为tcp的负载均衡器/反向代理
    具体参考Module ngx_stream_core_module

在看到ngx-rtmp代码中ngx_rtmp_init_connection 初始化的时候,有关于proxy_protocol的时候有点不明白,这个链接或者流也是从负载均衡器传过来的吗?

个人觉得:这个链接建立开始发送的是proxy_ptotocol的header,后续通过这个connection发送的数据都不加头,只是tcp数据而已了

listen 1936 proxy_protocol
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值