So quite a few months ago cPanel released an update that finally integrated Nginx. But alas that did not come without its issues.

 

Today I had an issue with a visit to one of my client’s sites and I asked the client to obtain the visitor’s IP address so that I don’t have to search through millions of logs, yes having COVID made me even lazier.

Well… upon checking logs I found out that my server’s IP was listed for all visits to the site… I checked other sites on this server and all that have Nginx enabled, have this issue.

The fix is quite easy. All you have to do is install an Apache module that is currently for some reason not available in the WHM EasyApache4 feature. It’s called mod_remoteip.
Apache’s mod_remoteip allows Apache to extract the visitor IP from requests received from proxies (in this case Nginx), load balancers and even in case you use CloudFlare’s proxy mode. This enables your website and logs to know the actual visitor IP instead of listing your server’s IP.

  1. Installing mod_remoteip on a cPanel server (as root):
    yum install ea-apache24-mod_remoteip
  2. Configuring apache to work with mod_remoteip:

    Copy the following in the /etc/apache2/conf.d/includes/pre_virtualhost_global.conf file.

    <IfModule remoteip_module>
     LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
     RemoteIPHeader X-Forwarded-For
     RemoteIPTrustedProxy YOUR-SERVER-IP
    </IfModule>

    That’s it! Now just do a graceful apache restart with your WHM or via your shell using:

    /scripts/restartsrv_httpd

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.