IBM Support

Setting the X-Forwarded-For header using IBM HTTP Server

Question & Answer


Question

How do I configure IBM HTTP Server to set a header called "X-Forwarded-For" equal to the IP address of the client?

Cause

The X-Forwarded-For header is not required by IBM HTTP Server (IHS) or by IBM WebSphere Application Server (WAS). But it may be required by software from other vendors.

Answer

For more information about the X-Forwarded-For header, see the definition on Wikipedia here: http://en.wikipedia.org/wiki/X-Forwarded-For

NOTES:
  • If IBM HTTP Server is located behind a Load Balancer or proxy server, using the method described below will probably not work as IBM HTTP Server will not get the real IP address of the client. In that case if the application needs to use X-Forwarded-For header, then it is the Load Balancer/ Proxy in front of IBM HTTP Server that needs to set that header.

To configure IBM HTTP Server to set the X-Forwarded-For header to the client IP address, in a non-proxy request, you need to enable the mod_rewrite and mod_headers modules, and then add the following lines in the IBM HTTP Server config (httpd.conf):
RewriteEngine on
# Set environment variable CLIENT_IP
RewriteRule ^(.*) - [E=CLIENT_IP:%{REMOTE_ADDR},L]
# Copy environment variable CLIENT_IP to X-Forwarded-For request header
RequestHeader set x-forwarded-for %{CLIENT_IP}e

In WebSphere Application Server, J2EE APIs that access the client IP address are not affected by the X-Forwarded-For header. The IBM web server Plug-in sends the client IP address to WebSphere Application Server in proprietary ($WS) headers. To learn more about HTTP headers, including the IBM $WS headers, please see the following webcast replay:
http://www.ibm.com/support/docview.wss?uid=swg27014842

[{"Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEQTJ","label":"IBM HTTP Server"},"ARM Category":[{"code":"a8m0z000000XasuAAC","label":"IHS-\u003EIHS.Config-\u003EIHS.Headers"}],"ARM Case Number":"TS004798015","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"},{"code":"PF035","label":"z\/OS"}],"Version":"All Version(s)"},{"Line of Business":{"code":"LOB67","label":"IT Automation \u0026 App Modernization"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"ARM Category":[{"code":"a8m0z000000XasuAAC","label":"IHS-\u003EIHS.Config-\u003EIHS.Headers"}],"Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"},{"code":"PF035","label":"z\/OS"}],"Version":"All Version(s)"}]

Document Information

Modified date:
11 March 2024

UID

swg21445012