您的位置:首页 > 运维架构 > 反向代理

nginx通过云负载均衡后作反向代理并限制制定ip访问

2017-12-28 17:01 429 查看
有个需求,需要特定的2个ip才能访问指定域名,但是使用私有云的slb负载后透过的ip,指向nginx反向代理后,使用nginx的ip限制无法控制ip访问。
试了很多办法但是没有效果,后来尝试了以下方式,发现可以了。

server {
listen       80;
server_name   xxx.xxx.xxx;

set $x $remote_addr;
if ($http_ali_cdn_real_ip) {
set $x $http_ali_cdn_real_ip;
}
#cms
location ^~ /cms {
proxy_pass http://pool_yyyy_8000/; proxy_set_header  Host  $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
client_max_body_size    100m;
set $allow true;
if ($http_x_forwarded_for !~ "xxx.xxx.xxx.xxx|yyy.yyy.yyy.yyy") {
set $allow false;
}
if ($allow = false) {
return 403;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息