Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Real client ip when using TIdHttpServer behind Apache proxy?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Oct 31, 2016 3:53 PM Last Post By: Remy Lebeau (Te...
Ahmed Sayed

Posts: 173
Registered: 8/9/07
Real client ip when using TIdHttpServer behind Apache proxy?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 31, 2016 6:20 AM
Hello everyone,

I am trying to get the actuall client IP address in TIdHttpServer
after using it as a backend behind apache server as a proxy server.

void __fastcall TDM::FServerConnect(TIdContext *AContext)
{
//std:map
TClientsList->Add(AContext->Connection->Socket->Binding->PeerIP, AContext);
}
//---------------------------------------------------------------------------


But I am getting either 127.0.0.1 or the real server ip not client's

In apache I am using this in config.

  ProxyRequests Off
  ProxyPreserveHost On
 
RemoteIPHeader X-Forwarded-For
 
<Location "/updater">
 
  Header set Connection close
 
  <LimitExcept GET>
    Order Allow,Deny
    Deny from all
  </LimitExcept>
 
  ProxyPass "https://localhost:8888/updater"
  ProxyPassReverse "https://localhost:8888/updater"
 
</Location>


Is it possible to X-Forwarded-For header from OnConnect event?

Any help would be appreciated regarding indy or apache?

--
The limits of my language mean the limits of my world
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Real client ip when using TIdHttpServer behind Apache proxy?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 31, 2016 3:53 PM   in response to: Ahmed Sayed in response to: Ahmed Sayed
Ahmed wrote:

But I am getting either 127.0.0.1 or the real server ip not client's

As you should be, since Apache is acting as a proxy, so the client is not
connecting directly to your TIdHTTPServer.

Is it possible to X-Forwarded-For header from OnConnect event?

No, because it is not available yet at that time. OnConnect will be triggered
when Apache makes a socket connection to your TIdHTTPServer, before it then
forwards any HTTP requests to you.

However, you can read the 'X-Forwarded-For' header in the OnCommand... events,
using the ARequestInfo->RawHeaders property, eg:

void __fastcall TDM::FServerCommandGet(TIdContext *AContext,
    TIdHTTPRequestInfo *ARequestInfo, TIdHTTPResponseInfo *AResponseInfo)
{
    String ClientIP = ARequestInfo->RawHeaders->Values["X-Forwarded-For"];
    if (ClientIP.IsEmpty())
        ClientIP = AContext->Connection->Socket->Binding->PeerIP;
    //...
}


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02