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

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

Open
jayliu3 opened this issue Nov 22, 2021 · 1 comment
Open

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

jayliu3 opened this issue Nov 22, 2021 · 1 comment
Labels
area/gateway-flow-control Issues or PRs related to API gateway flow control good first issue Good for newcomers kind/enhancement Category issues or prs related to enhancement.

Comments

@jayliu3
Copy link

jayliu3 commented Nov 22, 2021

因为使用了Nginx,针对请求的Client IP进行限流时有问题

image

所有请求获取到的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的方法

@sczyh30 sczyh30 added area/gateway-flow-control Issues or PRs related to API gateway flow control kind/enhancement Category issues or prs related to enhancement. good first issue Good for newcomers labels Nov 23, 2021
@icodening
Copy link
Contributor

这种不改源码的情况下,看样子是只能自己临时实现一个GatewayFilter了。我这打算提交一个可配置RequestItemParser的PR,这样就只需要自己配置一下获取remoteAddress逻辑即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/gateway-flow-control Issues or PRs related to API gateway flow control good first issue Good for newcomers kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants