Get real IP when using CloudFlare with Nginx / Apache

CloudFlare acts as a reverse proxy, so all connections to your server’s IP will be displayed with CloudFlare.

If your server configuration uses to IP, such as using firewall, log files … it is obligatory to adjust add additional steps to be able to operate stably.

the IP address of the original users are stored in the header X-Forwarded-for or header CF-Connecting-IP you use headers Whatever.

See also: Thiet ke biet thu dep

Get original IP client using CloudFlare with Nginx

Open Nginx configuration file, usually the path /etc/nginx/nginx.conf and place the real Nginx configuration later in the block IP module http .

 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 199.27.128.0/21;
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;

# Use any of the drop down two
CF-Connecting-IP real_ip_header;
X-Forwarded-For #real_ip_header;

In addition, you need to adjust the parameters to use log_format $ http_cf_connecting_ip or $ HTTP_X_FORWARDED_FOR as follows:

 main log_format '$ REMOTE_ADDR - $ REMOTE_USER [$time_local] $ status'
                '' $ Request "$ body_bytes_sent" $ HTTP_REFERER " '
                ' "$ HTTP_USER_AGENT" "$ http_cf_connecting_ip"';

Reload the Nginx to use the new configuration is complete.

List of IP needs to be updated from time to time, you can get the IP the latest here .

Get original IP client using CloudFlare with Apache

If using Apache Webserver, you can use the package available mod cloudflare .

1. Install the package needed

– Red Hat / Fedora:

 sudo yum install httpd-devel libtool git

– Debian / Ubuntu:

 sudo apt-get install apache2-dev libtool git

2. The latest Clone mod_cloudflare code

 && cd git clone https://github.com/cloudflare/mod_cloudflare.git mod_cloudflare

3. Compile the module

Red Hat / Fedora / Debain / Ubuntu:

 apxs -i -a -c mod_cloudflare.c

4. Restart the webserver and check the module was active

– Red Hat / Fedora:

 service httpd restart httpd -M && | grep CloudFlare

– Debian / Ubuntu:

 sudo apachectl restart; apache2ctl -M | grep CloudFlare

5. If your web server load balancer is used to add the following line to your Apache configuration file:

 CloudFlareRemoteIPTrustedProxy 123 123 123 123

More information here guidelines use CloudFlare and configure WordPress, Joomla …

Wish you success.

See more:

> Máy ép bùn khung bản tốt nhất Việt Nam

> Mẫu thiết kế biệt thự cao cấp nhất

> Thiết kế biệt thự cổ điển bởi Kiến Trúc AC

> Dự án thiết kế biệt thự Pháp đẹp

Get real IP when using CloudFlare with Nginx / Apache
3.3 (65.33%) 150 votes