I am aware of the headers CF-Connecting-IP
, $binary_remote_addr
, http_x_forwarded_for
I want to make a setting:
limit_req_zone $http_x_forwarded_for zone=k_request_limit_per_ip:10m rate=400r/s;
limit_conn_zone $http_x_forwarded_for zone=k_connection_limit_per_ip:10m;
But Cloudflare isn't the only place that this machine is going to be accessed, so I want to limit direct access too. Is there a way to write something like:
if(header == `X-Forwarded-For`) {
limit_req_zone $http_x_forwarded_for zone=k_request_limit_per_ip:10m rate=400r/s;
} else {
limit_req_zone $binary_remote_addr zone=k_request_limit_per_ip:10m rate=400r/s;
}
Or would something like this work:
limit_req_zone $http_x_forwarded_for zone=http_zone:10m rate=400r/s;
limit_req_zone $binary_remote_addr zone=binary_zone:10m rate=400r/s;
An alternative would be to fully allow all Cloudflare IP addresses. And limit the Non-Cloudflare IP addresses.
Good source: