This article contains information about configuring an Apache Web server to log client IP addresses based on the value contained within a custom HTTP header inserted by a NetScaler device.
Notes:
In most configurations, the responses from the Web servers pass through the NetScaler appliance, which reverses the address translation before forwarding the response to the client. This ensures that the internal Web servers are hidden from the client, who can access only the VIP address of the appliance, such as 10.2.3.4 in the example.
The issue with this configuration is that the Web server logs show the MIP address 10.5.6.7 for all client requests. This may not be desirable in environments that require the IP address of all Web accesses to be logged for accounting, security, or any other purpose.Configuring the NetScaler Appliance to Insert Client IP Address in a Custom HTTP Header
Configuring the Apache Web Server to Log the Client IP Address Available in the Custom HTTP Header
> set service <Service_Name> -cip ENABLED NS-Client-IP
Repeat the preceding command for every service that requires the client IP to be logged at the Apache Web server. In the preceding command, the NetScaler-Client-IP is the header name that is appended to the request. You can specify any name for the header.GET / HTTP/1.1 Host: www.example.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive NS-Client-IP: 10.60.1.166
Open the /opt/apache2/conf/httpd.conf file in a text editor, such as the vi editor.
Note: The path to the httpd.conf file might vary depending on the configuration of the Apache Web server. It is mostly available either in the <Apache_Install_Location>/conf/ or the /etc/ directory. Additionally, ensure that you make a backup of the configuration file before making any changes to it.
Append the following entries to the file:
LogFormat "%{NS-Client-IP}i %l %u %t \"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\"" ns-access CustomLog <Lof_File_Path>/<Log_File_Name> ns-access
Note: If the preceding entries already exist in the configuration file, then you can change the necessary changes to the entry. These entries change the parameters for an existing log file. However, if you add the preceding entries to the configuration file, then a log file is created to log client IP address with the specified parameters.
Save and close the configuration file.
Run the following command to restart the HTTP daemon:
# /opt/apache2/bin/httpd –k restart
Repeat this procedure on each Apache server in the farm.
The entries for the http.conf file specified in this document are just examples. You can make the required changes to suite the preference. Refer to the Apache HTTP server documentation for more details.
Additionally, the configuration specified in this document does not make the client IP address available to the Apache Web server to process the same. If you want to make the client IP address available for processing by the Apache Web server, then refer to the Knowledge Center article Custom Header Module for Apache 2.x to Process Client IP Address for further details.