Can I extract the last IP address in X-Forwarded-For and assign it to a variable

Maxim Dounin mdounin at mdounin.ru
Sat Jan 23 06:48:43 MSK 2010


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;
   }

Maxim Dounin



More information about the nginx mailing list