Nginx reverse proxy ratelimit

Hi,

I’ve set up a service with Docker and Nginx which aims to be a reverse-proxy and also to manage the ratelimit based on user IP addresses.

Currently, the service isn’t based on the visitor’s ip but on the node’s ip, which distorts the ratelimit.

How to make $binary_remote_addr take the value of the visitor’s ip address ?

Here’s what the configuration looks like:

limit_req_zone $binary_remote_addr zone=zone_1:10m rate=1r/s;

server {

server_name localhost;
listen 8000;
charset utf-8;

location / {

    limit_req zone=zone_1 nodelay;
    limit_req_status 429;

    proxy_pass https://url-of-my-service/;
    proxy_set_header x-forwarded-host $host;
    proxy_set_header X-Real-IP $remote_addr;
}

Thanks

Hi @jeremy_gaudin , did you try to get the remote IP address with $http_x_forwarded_for variable from NGINX?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.