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

help request: remote_addr is error #11907

Open
SandNight opened this issue Jan 12, 2025 · 4 comments
Open

help request: remote_addr is error #11907

SandNight opened this issue Jan 12, 2025 · 4 comments
Labels
question label for questions asked by users

Comments

@SandNight
Copy link

Description

local ip_address:192.168.26.161
Expect the $remote_addr to be 192.168.26.161
1.Client -> APISIX -> Upstream
2.apisix run in docker(docker inspect apisix)
"NetworkSettings": {
"Bridge": "",
"SandboxID": "ae0f9cefd5c76958555b2c0fc6241337d40b9d4ef6aa1846b254190d8d131b4a",
"SandboxKey": "/var/run/docker/netns/ae0f9cefd5c7",
"Ports": {
"9080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9080"
}
],
"9091/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9091"
}
],
"9092/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9092"
}
],
"9180/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9180"
}
],
"9443/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9443"
}
]
},
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"apisix_apisix": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"apisix",
"apisix"
],
"MacAddress": "02:42:ac:13:00:02",
"DriverOpts": null,
"NetworkID": "51637f90967a97ccaf0620591d8703912801d789ab544152f05fe09de56789cc",
"EndpointID": "c680a20c9f5ad8c0715efa84e82be9c609b23966580af50b66a17ed0f42f7d05",
"Gateway": "172.19.0.1",
"IPAddress": "172.19.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"DNSNames": [
"apisix",
"9980822c47bf"
]
}
}
}
3.route config
{
"id": "548570123204559551",
"create_time": 1736502873,
"update_time": 1736502873,
"uri": "/gateway/*",
"name": "router-01",
"methods": [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH",
"HEAD",
"OPTIONS",
"CONNECT",
"TRACE",
"PURGE"
],
"plugins": {
"response-rewrite": {
"headers": {
"set": {
"X-Server-balancer-addr": "$balancer_ip:$balancer_port",
"remote_addr": "$remote_addr",
"remote_port": "$remote_port",
"X-proxy_add_x_forwarded_for":"$proxy_add_x_forwarded_for"
}
}
}
},
"upstream": {
"nodes": {
"192.168.26.161:8062": 1
},
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"enable_websocket": true,
"status": 1
}
4.when I request http://192.168.26.161:9080/gateway/hello
response header remote-addr is 172.19.0.1
and
docker logs -f apisix
172.19.0.1 - - [12/Jan/2025:05:13:45 +0000] 192.168.26.161:9080 "GET /gateway/hello HTTP/1.1" 200 549 0.079 "-" "PostmanRuntime-ApipostRuntime/1.1.0" 192.168.26.161:8062 200 0.078 "http://192.168.26.161:9080"
this clien ip is 172.19.0.1 but the real client ip is 192.168.26.161

Environment

  • APISIX version (run apisix version):
  • apache/apisix:3.11.0-debian
  • Operating system (run uname -a):
  • Darwin JadeMac.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Jun 24 00:56:10 PDT 2024; root:xnu-8020.240.18.709.2~1/RELEASE_X86_64 x86_64
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • bitnami/etcd:3.4.15
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):
@dosubot dosubot bot added the question label for questions asked by users label Jan 12, 2025
@kayx23
Copy link
Member

kayx23 commented Jan 13, 2025

Could be attributed to Docker networking. Please see if real-ip plugin helps.

@SandNight
Copy link
Author

Could be attributed to Docker networking. Please see if real-ip plugin helps.

docker-compose.yml
version: "3"

services:
apisix-dashboard:
container_name: apisix-dashboard
image: apache/apisix-dashboard:3.0.1-alpine
restart: always
volumes:
- /Users/jade/docker/apisix/dashboard_conf/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml
ports:
- "9000:9000"
networks:
apisix:

apisix:
container_name: apisix
image: apache/apisix:v-3.11.0-x86
restart: always
volumes:
- /Users/jade/docker/apisix/apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
ports:
- "9180:9180/tcp"
- "9080:9080/tcp"
- "9091:9091/tcp"
- "9443:9443/tcp"
- "9092:9092/tcp"
networks:
apisix:

networks:
apisix:
driver: bridge

when I try use real-ip plugin , cause an exception.
real-ip config in etcd /apisix/route/xxx
"real-ip": {
"recursive": false,
"source": "http_x_forwarded_for",
"trusted_addresses": [
"127.0.0.0/24",
"172.20.0.0/24",
"10.100.48.0/24",
"192.168.185.0/24",
"192.168.1.0/24",
"192.168.164.0/24",
"10.80.9.0/24"
]
}

apisix logs (the ip is still wrong)
2025/01/12 05:13:45 [warn] 62#62: *8866 [lua] real-ip.lua:149: phase_func(): missing real address, client: 172.19.0.1, server: _, request: "GET /gateway/hello HTTP/1.1", host: "192.168.26.161:9080"
172.19.0.1 - - [12/Jan/2025:05:13:45 +0000] 192.168.26.161:9080 "GET /gateway/hello HTTP/1.1" 200 549 0.079 "-" "PostmanRuntime-ApipostRuntime/1.1.0" 192.168.26.161:8062 200 0.078 "http://192.168.26.161:9080"

when I use the model(Client -> Nginx -> APISIX -> Upstream)
I can get the right ip with real-ip plugin

@supreethmohan
Copy link

@SandNight I had a similar issue and adding the below apisix configuration in the httpSrv block of the nginx fixed the issue for me.
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
real_ip_recursive on;

Full block of code example: (line 476,477,478)

Image

@SandNight
Copy link
Author

@SandNight I had a similar issue and adding the below apisix configuration in the httpSrv block of the nginx fixed the issue for me. set_real_ip_from 0.0.0.0/0; real_ip_header X-Forwarded-For; real_ip_recursive on;

Full block of code example: (line 476,477,478)

Image

thank you!
I tried 3 different config in apisix(3.11) config.yaml
1.
nginx_config: # Config for render the template to generate nginx.conf
configurationSnippet:
main: |
httpStart: |
httpEnd: |
httpSrv: |
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
2.
nginx_config: # Config for render the template to generate nginx.conf
http:
real_ip_recursive: "on"
real_ip_header: X-Forwarded_For
real_ip_from:
- 0.0.0.0/0
3.
nginx:
configurationSnippet:
main: |
httpStart: |
httpEnd: |
httpSrv: |
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
real_ip_recursive on;

None of them can get the correct ip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question label for questions asked by users
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants