Cloudflare Original IP & Moddle issue

Cloudflare Original IP & Moddle issue

Khalil Ghanem -
Number of replies: 1

Greetings,

I'm having issues where moodle does not log the correct IP addresses, I did a lot of research and installed mod_remoteip  and changed some settings and it still does not record it properly.

What I'm using:

  • Centos 7 (Dedicated Server)
  • PHP 7.3
  • EasyApache 4
  • CPanel
  • NS: CloudFlare
  • Moodle 3.9.2

Some Useful Data: (PHP.INFO)

  • $_SERVER['REMOTE_ADDR'] = 162.158.166.93 (CloudFlare / Wrong IP)
  • $_SERVER['SERVER_ADDR'] = 45.58.***.*** (Real Server IP)
  • $_SERVER['HTTP_CF_CONNECTING_IP'] = 217.165.***.*** (My Real IP Address)
  • $_SERVER['HTTP_X_FORWARDED_FOR'] = 217.165.***.*** (My Real IP Address)


I tried changing the settings in Moodle -> Server -> HTTP -> "HTTP_CLIENT_IP, HTTP_X_FORWARDED_FOR, REMOTE_ADDR"

But that didn't work.

Please advise me on how to proceed or if im missing something ժպտում եմ

Վարկանիշների միջին թիվը. -
In reply to Khalil Ghanem

Re: Cloudflare Original IP & Moddle issue

Leon Stringer -
Core developers Նկարը Particularly helpful Moodlers Նկարը

So $_SERVER['HTTP_X_FORWARDED_FOR'] contains the IP address that should be logged? I think you just need to change Logged IP address source to "HTTP_X_FORWARDED_FOR, REMOTE_ADDR" in Moodle. Thus if HTTP_X_FORWARDED_FOR is present then this is the IP address that's logged. If it's not present then REMOTE_ADDR is logged.

I don't think you need mod_remoteip, this just tells Apache to substitute REMOTE_ADDR with whichever field you've specifed in RemoteIPHeader. You would use this only if you had a website (i.e. not Moodle) that did not read HTTP_X_FORWARDED_FOR.