• news
  • pics
  • linux
  • windows
  • proxmox
  • game
  • news
  • pics
  • linux
  • windows
  • proxmox
  • game
Home
linux

how to get real ip of user when you enable Cloudflare CDN for Nginx/Apache

Nginx part:

check if your nginx has http_realip_module.use command nginux -V

[[email protected] ~] # nginx -V
nginx version: nginx/1.14.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
built with OpenSSL 1.1.1a 20 Nov 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.1.1a --with-pcre=../pcre-8.42 --with-pcre-jit --with-ld-opt=-ljemalloc

add config into your nginx conf.

server {
         listen 80     ;
         server_name  www.rockfuns.com;    
location / {
    #cdn server ip
    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;
    real_ip_header CF-Connecting-IP;

    #your proxy config for apache 
    proxy_pass http://127.0.0.1:10000$request_uri;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}

apache part:

get rpaf from github. web address is https://github.com/gnif/mod_rpaf/
use apxs to install mod_rpaf.if you don’t have apxs command.Use yum install httpd-devel to get it.

 #on apache 1.3:
 apxs -i -a -c mod_rpaf.c 
 #on apache 2:
 apxs -i -c -n mod_rpaf.so mod_rpaf.c

Configuration Directives

RPAF_Enable             (On|Off)                
- Enable reverse proxy add forward

RPAF_ProxyIPs           127.0.0.1 10.0.0.0/24   
- What IPs & bitmasked subnets to adjust requests for

RPAF_Header             X-Forwarded-For         
- The header to use for the real IP address.

RPAF_SetHostName        (On|Off)                
- Update vhost name so ServerName & ServerAlias work

RPAF_SetHTTPS           (On|Off)                
- Set the HTTPS environment variable to the header value contained in X-HTTPS, or X-Forwarded-HTTPS. For best results make sure that mod_ssl is NOT enabled.

RPAF_SetPort            (On|Off)                
- Set the server port to the header value contained in X-Port, or X-Forwarded-Port. (See Issue #12)

RPAF_ForbidIfNotProxy   (On|Off)               
- Option to forbid request if not from trusted RPAF_ProxyIPs; otherwise cannot be done with Allow/Deny after remote addr substitution

Example Configuration

LoadModule              rpaf_module modules/mod_rpaf.so
RPAF_Enable             On
RPAF_ProxyIPs           127.0.0.1 10.0.0.0/24
RPAF_SetHostName        On
RPAF_SetHTTPS           On
RPAF_SetPort            On
RPAF_ForbidIfNotProxy   Off
Previous article centos firewall configuration
Next article 就在4月8日,IG要迎来一场硬仗!TheShy和Rookie将展开对峙

therock

16 Comments

  1. dirty keto diet
    July 9, 2021 at 5:05 am

    keto diet health risks

  2. what can you eat on keto diet
    July 9, 2021 at 1:59 am

    keto reset diet

  3. keto sauces
    July 7, 2021 at 9:30 pm

    keto diet for dummies

  4. dating sites free no subscription
    June 26, 2021 at 5:03 am

    free online dating site for 16-19 year olds

  5. free dating local sites
    June 24, 2021 at 5:24 pm

    legitimate free dating sites

  6. free dating and chating sites
    June 24, 2021 at 2:58 am

    best free dating sites in 1990

  7. 100 free dating sites reviews
    June 23, 2021 at 7:49 pm

    sugar daddy dating sites free for women

  8. dating in dubai free
    June 2, 2021 at 9:08 am

    free best dating sites

  9. german dating sites for free
    June 2, 2021 at 5:57 am

    shemale dating free

  10. free lgbt dating
    June 2, 2021 at 2:51 am

    uk free online dating

  11. free dating sites on facebook
    June 2, 2021 at 1:22 am

    search free dating site

  12. free south american dating sites
    May 20, 2021 at 8:50 pm

    germany free dating sites

  13. free french dating site
    May 20, 2021 at 7:52 pm

    100 free dating site in united state of america

  14. totally free canadian dating sites
    May 20, 2021 at 6:17 pm

    free online dating site for mobile

  15. bbw free online dating
    May 19, 2021 at 6:41 pm

    bbw free online dating

  16. fake number for tinder
    May 15, 2021 at 3:53 pm

    fake number for tinder

    how to get real ip of user when you enable Cloudflare CDN for Nginx/Apache – rock funs

Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Categories
  • game
  • linux
  • news
  • pics
  • proxmox
  • windows
Recent Posts
  • proxmox7.3直通显卡
  • Proxmox VE 直通显卡方案及解决N卡Code43
  • Linux系统出现:You have new mail in /var/spool/mail/root 的原因及解决办法
  • debian系统解决中文乱码
  • pve添加git和pvetools
Recent Comments
  • EdgarTot on proxmox7.3直通显卡
  • Ashvem on proxmox7.3直通显卡
  • Tedvem on proxmox7.3直通显卡
  • Jackvem on proxmox7.3直通显卡
  • Miavem on proxmox7.3直通显卡
Archives
  • March 2023 (1)
  • December 2022 (4)
  • November 2022 (6)
  • April 2022 (1)
  • February 2022 (5)
  • January 2022 (2)
  • December 2021 (3)
  • November 2021 (1)
  • October 2021 (2)
  • September 2021 (1)
  • August 2021 (1)
  • July 2021 (8)
  • June 2021 (14)
  • May 2021 (2)
  • April 2021 (2)
  • March 2021 (10)
  • January 2021 (4)
  • December 2020 (4)
  • November 2020 (13)
  • April 2020 (276)
  • March 2020 (1)
  • June 2019 (5)
  • May 2019 (10)
  • December 2015 (1)