nginx limit access whitelist for cloudflare

If you were using cloudflare protect your website, you may want to block other http request. 

Nginx can configure to block other ip range, you can try like this:

create a file, like /etc/nginx/whitelist/ip.conf

with content :

allow 10.0.0.0/8;
allow 192.168.0.0/16;
allow 172.16.0.0/12;
allow 173.245.48.0/20;
allow 103.21.244.0/22;
allow 103.22.200.0/22;
allow 103.31.4.0/22;
allow 141.101.64.0/18;
allow 108.162.192.0/18;
allow 190.93.240.0/20;
allow 188.114.96.0/20;
allow 197.234.240.0/22;
allow 198.41.128.0/17;
allow 162.158.0.0/15;
allow 104.16.0.0/12;
allow 172.64.0.0/13;
allow 131.0.72.0/22;

allow 2400:cb00::/32;
allow 2606:4700::/32;
allow 2803:f800::/32;
allow 2405:b500::/32;
allow 2405:8100::/32;
allow 2a06:98c0::/29;
allow 2c0f:f248::/32;

then add follow code into /etc/nginx/nginx.conf

    include whitelist/ip.conf;
    deny all;

Restart nginx, to see the result, other access will be blocked, user can only visit your website, via cloudflare

 

The latest cloudflare ip whitelist was:

https://www.cloudflare.com/ips/

 

Post: 2019-09-02 23:37:24

Views: 1

Follow me: @twitter @github
Scan QR code and Donate me via alipay:
donate me via alipay
Donate me Bitcoin:136MYemy5QmmBPLBLr1GHZfkES7CsoG4Qh
Powered by GoSense RSS