atom feed4 messages in ru.sysoev.nginxRe: Can I extract the last IP address...
FromSent OnAttachments
chittisJan 22, 2010 5:45 pm 
Maxim DouninJan 22, 2010 7:48 pm 
Subramanyam ChittiJan 23, 2010 3:02 am 
Maxim DouninJan 23, 2010 5:55 am 
Subject:Re: Can I extract the last IP address in X-Forwarded-For and assign it to a variable
From:Subramanyam Chitti (subr@gmail.com)
Date:Jan 23, 2010 3:02:48 am
List:ru.sysoev.nginx

Thanks a lot. This works perfectly. Is $1 always guaranteed to be the last IP in the X-Forwarded-For list? Is it the string that is matched in the $ position in the regular expression?

On Fri, Jan 22, 2010 at 7:48 PM, Maxim Dounin <mdou@mdounin.ru> wrote:

Hello!

On Fri, Jan 22, 2010 at 08:46:02PM -0500, chittis wrote:

I want to get the last IP address in the X-Forwarded-For header and assign it to a variable. I'm doing this using embeded perl now. Is there a way I can do this using the map module and regular expressions?

Map? Probably you mean rewrite? Try something like this:

  set $x "";   if ($http_x_forwarded_for ~ "(\d+\.\d+\.\d+\.\d+)$") {       set $x $1;   }