how to set squid proxy server to get client real ip address

2.4k Views Asked by At

My clients http requests go through Squid proxy server to connect to backend apache web server. A php script in the backend webserver gets clients' real ip address as below:

       if (!empty($_SERVER['HTTP_CLIENT_IP']))
       {
          $ip_address = $_SERVER['HTTP_CLIENT_IP'];
       }
       //whether ip is from proxy
       elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
       {
         $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
       }
       //whether ip is from remote address
       else
       {
         $ip_address = $_SERVER['REMOTE_ADDR'];
       }

I set the Squid proxy server with the following parameters in order to get the clients real ips:

    via on
    request_header_access  X-Forwarded-For  allow all
    forwarded_for   on
    follow_x_forwarded_for allow localhost

I expected to get the real clients' ips through the parameter $_SERVER['HTTP_X_FORWARDED_FOR']. However, when I checked the values from clients' browsers, only remote_addr has values:

  • http_client_ip: undefined
  • http_x_forwarded_for: undefined
  • remote_addr => squid proxy server ip address

I suspect the issue may locate in my squid proxy server setup, but have no idea which Squid configuration parameters should I change. Appreciated your help in advance.

With Regards

Steve

0

There are 0 best solutions below