Logging or Showing Real IP in cPanel/Apache when using CloudFlare

We recently switched to CloudFlare for our own website but even after a lot of research could not find proper documentation moreover mod_cloudflare has been discontinued and all documents are too old, so here is how we fixed it.

  1. First login to WHM
  2. Customise your Apache config and under Apache Modules select mod_remoteip (yes we will use mod_remoteip instead of mod_cloudflare)
  3. Once Apache is recompiled now you need to edit a file with name “370_mod_remoteip.conf” it may be 360 or 350 or something else but last part will be “mod_remoteip.conf” and file is available in /etc/apache2/conf.modules.d.
  4. Just add following to above file:

RemoteIPHeader X-Real-IP
RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 103.31.4.0/22
RemoteIPTrustedProxy 141.101.64.0/18
RemoteIPTrustedProxy 108.162.192.0/18
RemoteIPTrustedProxy 190.93.240.0/20
RemoteIPTrustedProxy 188.114.96.0/20
RemoteIPTrustedProxy 197.234.240.0/22
RemoteIPTrustedProxy 198.41.128.0/17
RemoteIPTrustedProxy 162.158.0.0/15
RemoteIPTrustedProxy 104.16.0.0/12
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22
RemoteIPTrustedProxy 2400:cb00::/32
RemoteIPTrustedProxy 2606:4700::/32
RemoteIPTrustedProxy 2803:f800::/32
RemoteIPTrustedProxy 2405:b500::/32
RemoteIPTrustedProxy 2405:8100::/32
RemoteIPTrustedProxy 2a06:98c0::/29
RemoteIPTrustedProxy 2c0f:f248::/32

 

5. Now go to WHM and under “Apache Configuration” click on “Include Editor” then under “Pre Main Include” edit the file and add:

<IfModule remoteip_module>
RemoteIPHeader X-Forwarded-For
</IfModule>
<IfModule log_config_module>
LogFormat “%{Referer}i -> %U” referer
LogFormat “%{User-agent}i” agent
LogFormat “%a %l %u %t \”%r\” %>s %b” common
LogFormat “%a %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
CustomLog logs/access_log combined
</IfModule>

 

Now just save and restart Apache, it should now start showing your real IP in apache logs etc…

 

 

 

Manually Migrate a KVM VPS to another node where both source and destination nodes are running SolusVM

If for some reason SolusVM automated migration is failing or if you just want make your hands dirty and wants to manually migrate a KVM VPS to another VPS Node, just follow these simple steps:

Run following commands on Source VPS Node:

Assuming your KVM ID for your VPS is “kvm5368”

# lvdisplay | grep kvm5368
LV Path /dev/vg_node10/kvm5368_img
LV Name kvm5368_img

Now lets shutdown the Source VPS:

# virsh shutdown kvm5368

Now once it’s shutdown lets create an image of the VPS Disk:

#dd if=/dev/vg_node10/kvm5368_img | gzip | dd of=/root/kvm5368_backup.gz bs=4096

Now lets create a Logical Volume on the destination node, so run following commands on the destination node:

# lvcreate -n kvm5368_img –size 30G /dev/vg_node

Now transfer the VPS image file created earlier from source to destination node:

# scp -C /root/kvm454_backup.gz root@destinationvpsnode:/root/

Once it’s transferred then run following command on destination vps node to restore the VPS Image:

dd if=/root/kvm5368_backup.gz | gzip -d | dd of=/dev/vg_node/kvm5368_img bs=4096

Once it’s restored run following command on your SolusVM Master:

/scripts/vm-migrate <vserverid> <newnodeid>

Now you should be able to boot the new migrated VM from SolusVM