Getting remot4e address

hi
i have haproxy running in front of nginx, and i have the
x-forwarded-for enabled in the haproxy configuration.
How do I configure nginx so that my fastcgi backends get this IP
address as the remote ip address and not the ip address of the
haproxy.

these are my fastcgi parameters

        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_script_name;
        fastcgi_param QUERY_STRING    $query_string;
        fastcgi_param CONTENT_TYPE    $content_type;
        fastcgi_param CONTENT_LENGTH  $content_length;
        fastcgi_param REQUEST_METHOD  $request_method;
        fastcgi_param REMOTE_ADDR     $remote_addr;
        fastcgi_param REMOTE_PORT     $remote_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SERVER_ADDR     $server_addr;
        fastcgi_param SERVER_PORT     $server_port;
        fastcgi_param SERVER_NAME     $server_name;

On Tue, Feb 26, 2008 at 11:58:16AM -0800, [email protected] wrote:

        fastcgi_param QUERY_STRING    $query_string;
        fastcgi_param CONTENT_TYPE    $content_type;
        fastcgi_param CONTENT_LENGTH  $content_length;
        fastcgi_param REQUEST_METHOD  $request_method;
        fastcgi_param REMOTE_ADDR     $remote_addr;
        fastcgi_param REMOTE_PORT     $remote_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SERVER_ADDR     $server_addr;
        fastcgi_param SERVER_PORT     $server_port;
        fastcgi_param SERVER_NAME     $server_name;
 location / {
      set  $addr  $remote_addr;

      if ($http_x_forwarded_for ~ "(^|,)\s*(\d+\.\d+\.\d+\.\d+)\s$") 

{
set $addr $1;
}

      ...
      fastcgi_param  REMOTE_ADDR   $addr;

On Tue, Feb 26, 2008 at 12:08 PM, Igor S. [email protected] wrote:

      }

      ...
      fastcgi_param  REMOTE_ADDR   $addr;

hi igor,
thanks for your reply.
i tried what you gave, and i still get only the ip address of the
haproxy in my backends,
how to fix?
thanks

this my config…
location / {
root /home/mark/work/pop;
fastcgi_pass backend_pop;
include /home/mark/work/infrastructure/nginx_fastcgi.conf;
}

file nginx_fastcgi.conf;
set $addr $remote_addr;

     if ($http_x_forwarded_for ~ "(^|,)\s*(\d+\.\d+\.\d+\.\d+)\s$") 

{
set $addr $1;
}

        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_script_name;
        fastcgi_param QUERY_STRING    $query_string;
        fastcgi_param CONTENT_TYPE    $content_type;
        fastcgi_param CONTENT_LENGTH  $content_length;
        fastcgi_param REQUEST_METHOD  $request_method;
        #fastcgi_param REMOTE_ADDR     $remote_addr;
        fastcgi_param REMOTE_ADDR     $addr;
        fastcgi_param REMOTE_PORT     $remote_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SERVER_ADDR     $server_addr;
        fastcgi_param SERVER_PORT     $server_port;
        fastcgi_param SERVER_NAME     $server_name;

On Tue, Feb 26, 2008 at 1:00 PM, Igor S. [email protected] wrote:

      if ($http_x_forwarded_for ~ "(^|,)\s*(\d+\.\d+\.\d+\.\d+)\s$") {

My mistake:

  •      if ($http_x_forwarded_for ~ "(^|,)\s*(\d+\.\d+\.\d+\.\d+)\s$") {
    
  •      if ($http_x_forwarded_for ~ "(^|,)\s*(\d+\.\d+\.\d+\.\d+)\s*$") {
    

igor:
now for ip in the fastcgi backend i get an empty string
‘ip’: ‘’

current config:
set $addr $remote_addr;
if ($http_x_forwarded_for ~ “(^|,)\s*(\d+.\d+.\d+.\d+)\s*$”)
{
set $addr $1;
}

On Tue, Feb 26, 2008 at 12:52:56PM -0800, [email protected] wrote:

           set  $addr  $1;

thanks

     if ($http_x_forwarded_for ~ "(^|,)\s*(\d+\.\d+\.\d+\.\d+)\s$") {

My mistake:

  •      if ($http_x_forwarded_for ~ 
    

“(^|,)\s*(\d+.\d+.\d+.\d+)\s$”) {

  •      if ($http_x_forwarded_for ~ 
    

“(^|,)\s*(\d+.\d+.\d+.\d+)\s*$”) {

On Tue, Feb 26, 2008 at 01:11:40PM -0800, [email protected] wrote:

haproxy in my backends,
set $addr $remote_addr;
if ($http_x_forwarded_for ~ “(^|,)\s*(\d+.\d+.\d+.\d+)\s*$”) {

  •      if ($http_x_forwarded_for ~ 
    

“(^|,)\s*(\d+.\d+.\d+.\d+)\s*$”) {

  •      if ($http_x_forwarded_for ~ 
    

“(?:^|,)\s*(\d+.\d+.\d+.\d+)\s*$”) {

On Tue, Feb 26, 2008 at 1:24 PM, Igor S. [email protected] wrote:

address as the remote ip address and not the ip address of the
hi igor,
‘ip’: ‘’

current config:
set $addr $remote_addr;
if ($http_x_forwarded_for ~ “(^|,)\s*(\d+.\d+.\d+.\d+)\s*$”) {

  •      if ($http_x_forwarded_for ~ "(^|,)\s*(\d+\.\d+\.\d+\.\d+)\s*$") {
    
  •      if ($http_x_forwarded_for ~ "(?:^|,)\s*(\d+\.\d+\.\d+\.\d+)\s*$") {
    
          set  $addr  $1;

works great now!!!
here is the final config:

     set  $addr  $remote_addr;
     if ($http_x_forwarded_for ~ 

“(?:^|,)\s*(\d+.\d+.\d+.\d+)\s*$”) {
set $addr $1;
}
thanks a lot