Plesk - Display Visitors' Original IP Addresses from Cloudflare

Introduction

The following Help Center article describes how to view the actual IP addresses of your website visitors in the web server logs if you are using Cloudflare as a reverse proxy in front of your Plesk server.


Prerequisites

  • Server with Plesk Control Panel



Procedure

Open your Plesk Control Panel in your browser and navigate to Websites & Domains โ†’ Your Domain โ†’ Hosting and DNS โ†’ Apache & nginx.


Then scroll down to the additional nginx directives and add the following entries there.

# Set the X-Forwarded-For header in relation to the "real_ip_header" module
real_ip_header X-Forwarded-For;

# Specify the Cloudflare IP addresses for which the original IP address should be displayed 
set_real_ip_from <IPv4 or IPv6>;
set_real_ip_from <IPv4 or IPv6>;


It is important to note that all current IPv4 and IPv6 addresses must be configured so that the real IP address can be displayed in the web server log for all connections.


If you have access to a command line, you can run the following command to generate all necessary set_real_ip_from entries for the current IP addresses:

curl -s https://www.cloudflare.com/ips-v4/# | sed 's|^|set_real_ip_from |; s|$|;|' && echo
curl -s https://www.cloudflare.com/ips-v6/# | sed 's|^|set_real_ip_from |; s|$|;|' && echo



The list of IP addresses in the screenshot above is incomplete and may contain outdated entries, among other things. Please refer to the text in the blue information box and, if possible, use the suggested commands to retrieve the current IP addresses or the corresponding entries.


Finally, save the changes by clicking the blue OK or Apply button.