How to log client IP address on cloudflare tunnel

24年 9月 26日 Thursday
151 words
1 minutes

How-to

I assume you've prepare everything needed to access your website globally via apache and cloudflare. In this tutorial, I setup a symlink on the /var/www directory to my home directory.

Take a look on the official documentation for the rest of tutorial

Overall steps are:

  • enable the mod_remoteip module
  • change LogFormat
  • restart apache

Additional notes

The command a2blabla is expected to be unavailable on non-Debian-based distributions.

if you encounter any 403 error, try to ensure the http user have correct permission:

text
sudo -u http ls -lah path-to-symlink

clear apache log by Tom O'Connor:

text
:>/var/log/httpd/the_file

Bonus

if you want to know how much machine visit your home, you can identify the machine based on IP address (assuming each machine only assigned one IP address):

text
awk '{print $1}' /var/log/httpd/access_log | sort | uniq

What next?

Log the client IP is useful if:

  • Your app need the client IP, well.. it's obvious reason.
  • You just simply want to observe who visit your home :3

See more about log format on Apache website

Title:How to log client IP address on cloudflare tunnel

Author:ReYuki

Link:https://www.reyuki.site/posts/log-client-ip-address [copy]

Last updated:


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. You are free to share and adapt it, as long as you give appropriate credit, don’t use it for commercial purposes, and distribute your contributions under the same license. Provided under license CC BY-NC-SA 4.0