Nginx/Haproxy作为反向代理或负载均衡时如何获取客户真实IP?

栏目: 服务器 · 发布时间: 7年前

内容简介:Nginx/Haproxy作为反向代理或负载均衡时如何获取客户真实IP?

Nginx代理配置

Contents

增加如下配置:

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_headerX_FORWARDED_PROTOhttps;
proxy_set_headerHost $host;
 

Haproxy配置

optionforwardfor
 
 

后端Nginx配置

set_real_ip_from  1.1.1.1;  前端Nginx代理或者负载均衡的IP(在后端Nginx日志中显示的)
real_ip_header  X-Forwarded-For;
real_ip_recursive  on;
 

后端Nginx访问控制

location ~ /test/api/ {
 
        set $allow false;
        if ($http_x_forwarded_for ~ "2.2.2.2") {
            set $allow false;
                        }
        if ($allow = false) { return 403;}
            proxy_pass  http://web;
        }
}
 

参考

  • http://www.wkii.org/nginx-cdn-get-user-real-ip.html

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Getting Started with C++ Audio Programming for Game Development

Getting Started with C++ Audio Programming for Game Development

David Gouveia

Written specifically to help C++ developers add audio to their games from scratch, this book gives a clear introduction to the concepts and practical application of audio programming using the FMOD li......一起来看看 《Getting Started with C++ Audio Programming for Game Development》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具