Score:0

How to split the 2 IP addresses appended by google cloud load balancer

br flag

I am using apache as my webserver for drupal. Also, I am using google cloud CDN and my instance is behind a load balancer (requirement for google cloud CDN). The issue is that the load balancer appends 2 IP addresses to the x-forwrded-for header as mentioned in this support document - https://cloud.google.com/load-balancing/docs/https#target-proxies

I want to split those IPs in apache's log and only keep the client IP from the 2 IP addresses that it appends. Please help

vn flag
You'll want https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html.
Score:1
br flag

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{x-forwarded-for-first}e\"" combined SetEnvIf X-Forwarded-For "^([^,]+)" x-forwarded-for-first=$1

This will produce logs in the following format: 127.0.0.1 - - [23/Dec/2022:12:34:56 +0100] "GET /index.html HTTP/1.1" 200 123 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36" "203.0.113.45"

The SetEnvIf directive uses the ^ character to match the start of the X-Forwarded-For header, and the ([^,]+) regular expression to match and capture the first IP address. The captured IP address is then stored in the x-forwarded-for-first environment variable.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.