Community

Show real visitor IP behind Cloudflare on CYBERPANEL not OLS

Ma
MarcoWB #2

Ok found the solution:

  1. Open /usr/local/lsws/conf/httpd_config.conf
  2. Add this on the first block of directives
    useIpInProxyHeader 1
    from what i understood 1 means that it works with all visitors coming from Cloudflare showing in the access.log the real ip instead the proxy’s ip.
    Instead 2 as option value means the same thing but limited on the ip addresses in the allowed list only.
    This should be to just “trust” on the allowed ips and avoid people faking this additional header value and so faking the ip in access log.
rs
rssperky #3

Can you make screenshot where to put it?

SD
SaJeTek Developer #4

The OLS WebAdmin setting is the same regardless of whether you're on CyberPanel or OpenLiteSPeed as it's in the OLS console at port 7080, not in CyberPanel itself.

Go to Server Configuration → General → Use Client IP in Header and set it to Trusted IP Only. Then add all Cloudflare CIDRs to your access control
allowed list with a T suffix (marks them as trusted).

One thing worth knowing: if you also have deny ALL in your access control, setting Trusted IP Only will break it. OLS then evaluates deny ALL against
the real visitor IP instead of the Cloudflare source IP, and visitors get 403.

The fix is to leave Use Client IP in Header = No with deny ALL and instead update your access log format to capture CF-Connecting-IP directly:

%{CF-Connecting-IP}i proxy: %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"

This gives you real IPs in logs, working deny ALL, and correct fail2ban parsing without changing the header setting.

Full walkthrough here: https://sajetekengineering.com/blog-article/how-to-allow-only-cloudflare-ips-on-openlitespeed-without-getting-403-errors/

Sign in to reply