在 AWS ALB 后面的容器上获取客户端真实 IP
Get Client Real IP on Container Behind AWS ALB
我在 AWS Application Load Balancer 后面的 EC2 实例中有一个容器 运行。
容器 运行 使用 network_mode=host 并显示请求信息和 Header 的简单 JSON。
问题是,我没有获得客户端真实 IP。相反,我在 X-Forwarded-For
Header.
中获得了一个内部 IP
另外:
- ALB 方案是内部的
- 我们使用企业代理
我错过了什么?
JSON 响应:
{
"path": "/",
"headers": {
"x-forwarded-for": "10.XXX.XX.XX",
"x-forwarded-proto": "http",
"x-forwarded-port": "80",
"host": "test.com",
"x-amzn-trace-id": "Root=1-XXXXXXX",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 ...",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-encoding": "gzip, deflate",
"accept-language": "en-US,en;q=0.9",
"cookie": "XXXX"
},
"method": "GET",
"body": "",
"fresh": false,
"hostname": "test.com",
"ip": "::ffff:10.YYY.YY.YY",
"ips": [],
"protocol": "http",
"query": {},
"subdomains": [
"test"
],
"xhr": false,
"os": {
"hostname": "ec2-instance"
}
}
回答我自己的问题。
碰巧out内部LoadBalancer前面有一个NLB
我在 AWS Application Load Balancer 后面的 EC2 实例中有一个容器 运行。
容器 运行 使用 network_mode=host 并显示请求信息和 Header 的简单 JSON。
问题是,我没有获得客户端真实 IP。相反,我在 X-Forwarded-For
Header.
另外:
- ALB 方案是内部的
- 我们使用企业代理
我错过了什么?
JSON 响应:
{
"path": "/",
"headers": {
"x-forwarded-for": "10.XXX.XX.XX",
"x-forwarded-proto": "http",
"x-forwarded-port": "80",
"host": "test.com",
"x-amzn-trace-id": "Root=1-XXXXXXX",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 ...",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-encoding": "gzip, deflate",
"accept-language": "en-US,en;q=0.9",
"cookie": "XXXX"
},
"method": "GET",
"body": "",
"fresh": false,
"hostname": "test.com",
"ip": "::ffff:10.YYY.YY.YY",
"ips": [],
"protocol": "http",
"query": {},
"subdomains": [
"test"
],
"xhr": false,
"os": {
"hostname": "ec2-instance"
}
}
回答我自己的问题。
碰巧out内部LoadBalancer前面有一个NLB