alibaba / alibaba/Sentinel

Nginx代理后如何针对请求的Client IP进行限流

Open
#2,456 1 comment 0 reactions 0 assignees View on GitHub
area/gateway-flow-control good first issue kind/enhancement
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## 因为使用了Nginx,针对请求的Client IP进行限流时有问题
![image](https://user-images.githubusercontent.com/24456816/142847227-d3f74c67-3aca-4945-965d-472413cc8bec.png)

`所有请求获取到的ip地址都为同一个地址172.*.*.*,(应用部署在docker容器内)。`

看了下com.alibaba.csp.sentinel.adapter.gateway.sc.ServerWebExchangeItemParser#getRemoteAddress的方法,获取ip时使用的代码是
```
public String getRemoteAddress(ServerWebExchange exchange) {
InetSocketAddress remoteAddress = exchange.getRequest().getRemoteAddress();
return remoteAddress == null ? null : remoteAddress.getAddress().getHostAddress();
}
```
是否可以自定义获取请求ip地址?或者可以让sentinel得到代理后真实请求ip的方法

Contributor guide

Open the contributing guide

Research direction

Start with com.alibaba.csp.sentinel.adapter.gateway.sc.ServerWebExchangeItemParser#getRemoteAddress and reproduce the reported client-IP behavior through Nginx into the Docker-deployed application. Check how the gateway adapter obtains the request address and determine whether proxy-aware or configurable address handling is supported; done means requests are rate-limited by the real client IP rather than the shared 172.*.*.* address.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, nginx
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.