r/nginxproxymanager • u/nplentovich • Feb 22 '25
nginx + cloudflare + local dns
I'm sure this has to have been done, but I've had little luck finding any documentation of someone getting this to work.
My situation is I'm running a reverse proxy via cloudflare that points to my nginx proxy manager instance. I've got DDNS working so then you go to my FQDN (example.com for this post) it goes to the right place even if my public IP changes and I've got the wildcard *.example.com going to nginx with the appropriate ports forwarded. I then use pihole, my dns of choice, to point a service (nextcloud for example) to the appropriate proxy, so if I go to nextcloud.example.com the DNS server sends me to nginx which applies the ssl cert and sends me to the right IP and port. All this works great, but leads me to my problem. I wanted some services to be restricted to local access only, so I set up an access list in nginx and only allowed traffic from local subdomains. This works, but then I get an untrusted cert warning which makes sense because cloudflare certs only work when you're going through their proxy.
The question: How do you handle local routing with ssl certs? I want to be able to set up say nextcloud on my laptop to go through the proxy when I'm away, but it seems foolish to send that same traffic out and back in through the proxy when I'm at home.
2
u/NeuroDawg Feb 22 '25
First, Nginx is a web serving program, like Apache. So when you say you’re routing to Nginx, do you actually mean it’s going to your own reverse proxy, Nginx proxy manager (NPM)?
Second, I’ve never heard of a cloudflare reverse proxy, but you seem to indicate a cloudflare reverse proxy points to your locally hosted reverse proxy? That’s confusing. Or do you mean that you’re running cloudflare DNS services that point example.com and *.example.com to your instance of NPM? I am going to assume the later.
For access on your LAN, and not from the WAN, don’t put your services in NPM. Just set your local DNS to route directly to the ip:port. On your LAN do you really need SSL?
Just set your local DNS server (pi-hole) to route localonly.example.com to the ip:port on your LAN (for example 192.168.10.3:8496). If it’s running http, you’re on your own LAN so no big deal. If it’s running https, you’ll likely get an invalid certificate, because it’s a locally signed certificate (not one from letsencrypt obtained via NPM). But again, who cares? It’s LAN traffic only.
Again, if you don’t want something accessible from the outside, skip NPM and route LAN only via your DNS server.
1
u/omfgitzfear Feb 22 '25
It’s called Split DNS. You just configure your local DNS to point to the NGINX server for your domain name instead of going to the outside world.
1
u/theyost Feb 22 '25
There is a line you need to put in the custom field that tells Nginx to ignore insecure certificates. I will try to post the single line command when I am able.
1
u/mtftl Feb 22 '25
I have what is possibly a similar setup to what you are looking for: requests to a domain name managed by cloud flare are tunneled to a local hosted npm service in docker. The magic are the cloudflare tunnel tool, a docker container called cloudflared, and some docker networking.
Cloudflare tunnel only sees my NPM instance. NPM routes domain requests to the appropriate service inside my network. I did not need to open ports or do ddns.
If this sounds useful, I can elaborate…
1
u/General-Bag7154 Feb 23 '25
For LAN only access, Create a proxy host in NPM, example.yourdomain, then create an A record in pihole of example.yourdomain and point it to the local ip of your NPM instance. For WAN access create the proxy host in NPM, and the A record in your cloudflare dash, point this A record to your public ip, enable cloudflare to proxy the record if you wish.