Obtaining the connecting clients IP address (Real IP) with cPanel

cPanel is a Linux based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides capabilities for administrators, resellers, and end-user website owners to control the various aspects of website and server administration through a standard web browser.

cPanel Method (Apache/httpd):

cPanel uses Apache which allows you to use the mod_rpaf module, all that is required is for the module to be installed and enabled in cPanel.

  1. Login to your server using the Secure Shell (SSH) credentials provided to you and enter the below mentioned commands to install mod_rpaf on a cPanel Server.

  2. Run the commands below to download mod_rpaf and install it alongside Apache.

    cd /usr/local/src
    wget http://mirror.trouble-free.net/sources/mod_rpaf-0.6.tar.gz
    tar -xzf mod_rpaf-0.6.tar.gz
    cd mod_rpaf-*
    apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
  3. First login to WHM as administrator

  4. Once installed, we need to load the module into Apache configuration. Since cPanel already has Include Editor for Apache, we will use that function. Service Configuration > Apache Configuration > Include Editor > Pre Main Include > All Versions and paste following text:

    LoadModule rpaf_module modules/mod_rpaf-2.0.so
    RPAFenable On
    RPAFsethostname On
    RPAFheader X-Real-IP

    Where is your proxy IP.

  5. Next click Update > Restart Apache. The module should be loaded after restart.

  6. To ensure that cPanel will remember that Apache configuration template has changed we need to run the following commands:

    /usr/local/cpanel/bin/apache_conf_distiller --update --main

More Information

More information on the X-Real-IP header can be found here. More information on cPanel can be found on their website cPanel. More information on the Apache (httpd) web server can be found on the project website and documentation for the mod_rpaf module.