Get real IP address of visitor for Cloudflare nGinx solution
When you have setup your web sites on cloudflare, every visitor who visits your web site passes through cloudflare network so that his real IP gets changed into cloudflare’s IP address, in short cloudflare acts as proxy server for your web server.
For apache web server, cloudflare has already provided a module which can be installed to get real ip address of visitor.
Here it is :
Well they do not provide any module for nGinx, however it is built in function in nGinx server. You can enable it by adding following below code into your nginx.conf
Follow below steps:
Find nginx.conf file if you do not know the exact location from SSH:
# locate nginx.conf
Add below code in nginx.conf under http section:
set_real_ip_from 220.127.116.11/24; set_real_ip_from 18.104.22.168/24; set_real_ip_from 22.214.171.124/21; set_real_ip_from 126.96.36.199/20; set_real_ip_from 188.8.131.52/22; set_real_ip_from 184.108.40.206/18; set_real_ip_from 220.127.116.11/18; real_ip_header CF-Connecting-IP;
Now save changes and restart your nginx server
service nginx restart
That is all, now you will be able to get real ip address of the visitor.
Comments are welcome.