- Prestashop
- 0 likes
- 1088 views
- 0 comments

Cloudflare adds headers X-Forwarded-For and CF-Connecting-IP with original visitor IP address. So, we need to change nginx config to see original visitor IPs in Prestashop store.
You need installed nginx with ngx_http_realip_module module.
Include the following parameters to the http {} section:
Create file cloudflare in /etc/nginx/ directory with following entry:
set_real_ip_from 103.21.244.0/22; set_real_ip_from 103.22.200.0/22; set_real_ip_from 103.31.4.0/22; set_real_ip_from 104.16.0.0/12; set_real_ip_from 108.162.192.0/18; set_real_ip_from 131.0.72.0/22; set_real_ip_from 141.101.64.0/18; set_real_ip_from 162.158.0.0/15; set_real_ip_from 172.64.0.0/13; set_real_ip_from 173.245.48.0/20; set_real_ip_from 188.114.96.0/20; set_real_ip_from 190.93.240.0/20; set_real_ip_from 197.234.240.0/22; set_real_ip_from 198.41.128.0/17; set_real_ip_from 2400:cb00::/32; set_real_ip_from 2606:4700::/32; set_real_ip_from 2803:f800::/32; set_real_ip_from 2405:b500::/32; set_real_ip_from 2405:8100::/32; set_real_ip_from 2c0f:f248::/32; set_real_ip_from 2a06:98c0::/29; real_ip_header CF-Connecting-IP;
Open /etc/nginx/nginx.conf and add in http {} section include cloudflare.
Save file.
To Include the original visitor IP in your logs, add the variables $http_cf_connecting_ip and $http_x_forwarded_for in the log_format directive.
Check nginx configuration:
nginx -t
If no errors there - you can restart nginx to apply new configuration:
-
for CentOS/RHEL:
systemctl restart nginx
-
for Ubuntu:
service nginx restart
Check your site and take a look at the error log (/var/log/nginx/..)
Optional
If some Prestashop modules need to catch Real IP into $_SERVER['REMOTE_ADDR'] variable, you may need to add also fastcgi_param REMOTE_ADDR $http_x_real_ip; after fastcgi_pass line
Good luck!
Comments (0)
New comment