0

Is there any way how to use hosts.allow and hosts.deny files to restrict access to the websites (Nginx)?

This does not work:

hosts.allow file content:
nginx: SOME-IP-ADDRESS

hosts.deny file content:
nginx: ALL

I am going to use Cloudflare services and want allow connections to Nginx only from Cloudflare IP addresses but can't find a way how to do it.

Yes, I know, I can allow/deny connections by IP address in Nginx configuration file but not in this case because I use:

set_real_ip_from CLOUDFLARE_IP_ADDRESSES;
real_ip_header CF-Connecting-IP;

which converts Cloudflare IP addresses into users IP addresses and after that I can not know if the request is coming from Cloudflare. I want to allow connections only from Cloudflare but at the same time I want to know the real IP address of each http request.

Any ideas?

2
  • Just drop the non cloudflare connections at the firewall then – Drifter104 Mar 16 '16 at 10:09
  • Is there any way this is the same as "does hosts.allow work?" - of course it works. – AD7six Jun 14 '16 at 9:26
0

Only allow CloudFlare IP addresses through your firewall.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.