mirror of
https://github.com/ergin/nginx-cloudflare-real-ip.git
synced 2026-04-25 05:15:53 +03:00
[GH-ISSUE #3] Solution to detect the real ip while blocking non cloudflare #3
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/nginx-cloudflare-real-ip#3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @aseques on GitHub (May 27, 2019).
Original GitHub issue: https://github.com/ergin/nginx-cloudflare-real-ip/issues/3
I'll post here the final approach I took to get at the same time
Add to nginx.conf (http scope):
In the server block:
Being allow_cloudflare.conf the following:
This works like a charm, if you still want extra security you can configure the firewall to block the other ips but it's not needed.
@Nottt commented on GitHub (May 27, 2019):
This doesn't seem to be more secure than just white-listing cloudflare IP's with
ufwand blocking everything else.You are still allowing traffic from any IP to any open ports in your system
@aseques commented on GitHub (May 27, 2019):
It's not more secure, but it's more flexible, for example in my case I have a server that includes some internal sites only accessible via cloudflare access (those are restricted to the connections allowed in cloudflare access) and some sites that have public resources not protected by cloudflare.
Being behind a firewall is fine, but sometimes it's a pain to debug when there are issues.
@ankorez commented on GitHub (Aug 17, 2023):
Thank you very much for this solution i appreciate it
@forgotPassword commented on GitHub (Feb 2, 2024):
@aseques Note that attacker can easily have "cloudflare ip", by using cloudflare workers etc. So it is probably misleading thinking your are "safe" and blocked all evil actors.
You also might not want to advertise what domain you are expecting, by having a first rule to deny all un-matched server_name(s).
See also https://news.ycombinator.com/item?id=26688390
@aseques commented on GitHub (Feb 5, 2024):
hi @forgotPassword good to know, some notes about your points:
If a Cloudflare customer has configured their origin server to respond only to Cloudflare IPs, then they MUST also verify that the "Host" header on any request actually matches their domain name.Thanks for your notes
@ankorez commented on GitHub (Feb 5, 2024):
allow-cloudflare.sh.Make the script executable with the command:
chmod +x allow-cloudflare.sh.Execute the script with
./allow-cloudflare.sh.Allow SSH before enabling the firewall
Create a new configuration file in
/etc/nginx/conf.d/nginx-cloudflare-realip.confand add the following content:@aseques commented on GitHub (Feb 5, 2024):
@ankorez it doesn't help when you need two different services in the same IP, one restricted to cloudflare and the other open internet-wide
@forgotPassword commented on GitHub (Feb 24, 2024):
Another option is to use Authenticated Origin Pulls
You can even configure per hostname certs, which should solve the shared cloudflare network access problem. Another benefit is that you don't need to fuss with different ips. Only downside is probably loss of some cpu cycles.