Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
ProGet Package Download Statistics IP when behind Load Balancer
-
Hi,
We are running 2x ProGet servers in High Availability behind a load balancer. We are only seeing the load balancer IP on the package download statistics in ProGet.
We have enabled X-Forwarded-For on the load balancer to forward on the Client-IP but this has had not had any impact. Is there another header value we should be sending? Apologies if this is documented somewhere, I couldn't find it!
Thanks,
Ashely
-
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
stripIpv4OverIpv6bits may be relatively new.Thanks,
Alana