Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

从函数计算网关拿不到 IP 信息 #761

Closed
hbrls opened this issue Dec 16, 2020 · 4 comments
Closed

从函数计算网关拿不到 IP 信息 #761

hbrls opened this issue Dec 16, 2020 · 4 comments
Assignees

Comments

@hbrls
Copy link
Contributor

hbrls commented Dec 16, 2020

现象:this.ctx.ip 和 this.ctx.request.ip 为空

相关代码可能是: this[EVENT].clientIP

return this[EVENT].clientIP || this[EVENT].requestContext?.sourceIp || '';

如果在 egg 中配置 config.proxy = true,然后传入 X-Forwarded-For 是能按照约定取到值的

所以猜测是网关和应用之间传漏了

@echosoar
Copy link
Member

由于函数内是通过unix domian socket将请求转发给egg处理,这个过程中无法传递socket.remoteAddress,只能开启 proxy 从header中的 X-Forwarded-For 来获取,不过我们进行一下处理,如果开启了proxy就自动把context.ip赋值到X-Forwarded-For上面,不需要再单独传递了

@hbrls
Copy link
Contributor Author

hbrls commented Dec 17, 2020

其实是想拿到 socket.ip,想拿到的数据类似是 ['客户端 Chome 的 ip', '自建网关 nginx 的 ip', '阿里云函数网关 ip'] 这样的从外往里的数组

@echosoar
Copy link
Member

阿里云fc的http触发器传入的Request上面仅有clientIP,所以拿不到太多数据。

refs: https://help.aliyun.com/document_detail/74757.html

@VFVrPQ
Copy link

VFVrPQ commented Nov 13, 2023

所以该怎么解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants