Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Using X-Forwarded-For request header in classic http application load balancer

Hi everyone,

I have a global external http load balancer (CLASSIC) and want to use the X-Forwarded-For request header to route traffic between 2 backend services, all this in the url map.  I haven't accomplish this until now. It seems to me that the LB is not allowing it.

Does anyone have any advice?

Thanks.

 

1 4 2,695
4 REPLIES 4

Hi @ajuarez ,

This setting can't be achieved as HTTP(S) Load Balancer does not directly support routing based on the X-Forwarded-For header. The load balancer primarily uses layer 7 (application layer) information like URL paths, hostnames, or other layer 7 data for routing.

If you need to route traffic based on the client's IP address (which would typically be in the X-Forwarded-For header), you might need to consider other solutions or workarounds. For example:

1. Google Cloud Armor can be set up to permit or restrict traffic according to specified IP addresses or ranges. Although it doesn't precisely route traffic based on X-Forwarded-For, it provides a means to manage access by focusing on IP addresses.

2. You could implement a proxy or firewall positioned ahead of your backend services, handling routing decisions based on the X-Forwarded-For header.

Thank you Marvin, I achieved this by creating a virtual path for my application, then, I check the client IP address and send desired clients to that path. Finally in the LB use URL path for routing.

How can I enable x-forwarded-for in global external application load balancer ?

Hi amitgupta1,

I think you don't have to, as far as I know it is enabled already. The LB is send it to your backend, you can catch it in there.