作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有网站服务器,它有两个代理(鱿鱼,CF),它们使用不同的 header 来获取真实的 ip。
我猜 nginx 命令
set_real_ip_from ;real_ip_header X-Forwarded-For;
set_real_ip_from ip_from_proxy_one
real_ip_header X-Forwarded-For; // if from proxy one, then get ip from X-Forwarded-Forset_real_ip_from ip_from_proxy_two
real_ip_header X-CF-connecting-ip; // if from proxy two, then get ip from X-CF-connecting-ip
最佳答案
对于任何寻找解决方案的人,我想出了 this approach .
您可以看到可以根据外部服务 IP 地址设置映射以定义定义使用哪个 HTTP header 的变量,然后设置 real_ip_header
使用那个变量。但以下不能用 因为变量没有被解析为 real_ip_header
:
# DDoS protection service
geo $use_x_real_ip {
default 0;
186.2.160.0/24 1;
}
# Cloudflare
geo $use_x_cf_connecting_ip {
default 0;
103.21.244.0/22 1;
103.22.200.0/22 1;
103.31.4.0/22 1;
# all other Cloudflare's ranges ...
}
map "$use_x_real_ip:$use_x_cf_connecting_ip" $real_ip_header {
default 'X-Forwarded-For';
"1:0" 'X-Real-Ip';
"0:1" 'CF-Connecting-IP';
}
# here, the real IP header will be set to either X-Real-Ip or CF-Connecting-IP
real_ip_header $real_ip_header;
关于nginx - 如何从两个代理中识别realip? (nginx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24088047/
我已经在 AWS 机器上上传了 composer-rest-server ,我成功地启动了 composer-rest-server ,尽管它总是引用 http://localhost:3000 ,
我是一名优秀的程序员,十分优秀!