Hi @Ashley ,
It sounds like you're definitely looking in the right place / setting the right configuration. X-Forwarded-For should do the trick, but something as silly as a typo (which I've done several times) will make it not work.
Here are the settings we recommend:
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Port $server_port;
And as an FYI, here is the code we use to get the ClientIP adddress.
public static string GetClientIPAddress(this AhHttpRequest request)
{
ArgumentNullException.ThrowIfNull(request);
var forwardedFor = request.Headers["X-Forwarded-For"];
if (!string.IsNullOrWhiteSpace(forwardedFor))
{
var ips = forwardedFor.Split(',');
var clientIp = ips.FirstOrDefault();
if (!string.IsNullOrWhiteSpace(clientIp))
return stripIpv4OverIpv6(clientIp.Trim().Truncate(50)!);
}
return stripIpv4OverIpv6((request.NativeRequest?.HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? request.UserHostAddress).Truncate(50)!);
static string stripIpv4OverIpv6(string ip)
{
if (ip.StartsWith("::ffff:") && ip.Contains('.'))
return ip["::ffff:".Length..];
return ip;
}
}
Although I think the stripIpv4OverIpv6 bits may be relatively new.
Thanks,
Alana