1. cdn转发后,如何获取真实ip
1.1 生成密钥
在本地或服务器生成一个随机串:
yaml
openssl rand -hex 32这个值只放两处:
- EdgeOne 项目的环境变量
- 1Panel 的 Nginx 配置
1.2 1Panel 关闭「真实 IP」
进入 网站 → appapi.chituhub.com → 真实 IP:
因为这个功能不支持读密钥
1.3 1Panel 反代配置加密钥判断
编辑:
代码块
text
/www/sites/appapi.chituhub.com/proxy/*.conf在 location / 里、proxy_pass 之前加:
代码块
text
location ^~ / {
set $forwarded_client_ip $realip_remote_addr;
if ($http_x_proxy_secret = "新密钥") {
set $forwarded_client_ip $http_x_real_ip;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $forwarded_client_ip;
proxy_set_header X-Forwarded-For $forwarded_client_ip;
proxy_set_header X-Proxy-Secret "";
proxy_set_header REMOTE-HOST $forwarded_client_ip;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://127.0.0.1:20118;
proxy_http_version 1.1;
add_header X-Cache $upstream_cache_status;
proxy_ssl_server_name off;
proxy_ssl_name $proxy_host;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
}说明:
- 密钥匹配:把 EdgeOne 传来的真实客户端 IP 转给 Rust
- 密钥不匹配:用
$remote_addr,也就是真实连接 IP X-Proxy-Secret不继续传给后端,清空
2. edgeone配置

