What you need
- At least one server.
- At least one client.
- Access to your router (I use Tailscale, which makes things way easier than just using my home router).
- A server with Pi Hole.
- All of your servers must have Nginx Proxy Manager.
Getting started
Firstly, you must add your Pi Hole's IP address to your DNS settings in your router. How do you do this? It will vary from router to router. If you use Tailscale like me, go to Tailscale, sign in, go to the Admin Console, click DNS, and add your Pi Hole's Tailnet IP address to the "Global nameservers." Enable "Override local DNS" so that the rest of your Tailscale devices don't listen to the default DNS settings that's provided by Tailscale.
What to do in Pi Hole
In your Pi Hole configuration, go to Settings → DNS → and select "Permit all origins" in the Interface settings section. If you need more help with it, Tailscale has an article explaining more here.
While in Pi Hole, click on the "Local DNS" drop down on the left pane. Click "DNS Records." This is where you will add each of your server nodes via A and AAAA records.
In the domain section, type [hostname of your computer].lan
, as this is how you will refer to the node. For the IP Address section, enter the IP address of the server you are trying to access.
At this point, you should have your DNS server routed to your router and your server routed to your DNS server. While connected to your router, test the connection by going to your web browser (or however you access your services) and type [whatever hostname you put in pi hole].lan:[port that your service is running]
.
Example: myserver.lan:80
, which would be an HTTP service.
If you can access your service this way, you have done everything right so far. Next, go the CNAME Records section in Pi Hole. This section is similar, only you'll be putting the DNS record that you've made for your server in the "Target Domain" textbox. For the "Domain" section, put this: [service name].[hostname].lan
. Again (and to clarify), the "Target Domain" will basically just be [hostname].lan
.
What to do in Nginx Proxy Manager
Firstly, it should be mentioned that you must install Nginx Proxy Manager on the servers that you would like to add subdomains to. So, if I have services on server2 but Pi Hole is on server1, I need to add Nginx Proxy Manager on server2. "But I also have services on server1. What do I do?" Put Nginx Proxy Manager on server1 as well. For this configuration to work, you must add Nginx Proxy Manager to the servers you would like to add subdomains for.
On this topic, you must add a DNS record for each server running Nginx Proxy Manager. As for the CNAME record, I have my Nginx Proxy Manager set to npm (so, npm.server1.lan
, npm.server2.lan
, etc.)
With the important stuff out of the way, this part of the tutorial assumes that you already have Nginx Proxy Manager installed and otherwise configured (near) correctly.
Go to the Proxy Hosts section within NPM, click "Add Proxy Host." Here, you will be able to add whatever domain name you have entered in the CNAME section in Pi Hole in the "Domain Names" textbox as well as the Hostname you setup in the DNS Records (also in Pi Hole) in the "Forward Hostname / IP" textbox. As for the "Forward Port" textbox, enter the port that is used to access the service. Click "Save" to save the configuration.
At this point, you should have a similar configuration:
- DNS setting in router:
[Pi Hole's IP address]
. - DNS Interface settings in Pi Hole: Permit all origins.
- DNS Records in Pi Hole:
server1.lan
,server2.lan
, etc. -
CNAME Records in Pi Hole:
-
server1 (the one with Pi Hole):
pihole.server1.lan
npm.server1.lan
[service-name].server1.lan
-
server2 (the if you have a second server or multiple servers):
npm.server2.lan
[service-name].server2.lan
-
Proxy Hosts in NPM:
-
server1:
-
Pi Hole:
- Domain Names:
pihole.server1.lan
- Forward Hostname / IP:
server1.lan
- Forward Port:
8800
(this is the port I use. Enter whatever port you're using for Pi Hole).
- Domain Names:
-
Nginx Proxy Manager:
- Domain Names:
npm.server1.lan
- Forward Hostname / IP:
server1.lan
- Forward Port:
81
(we don't have to forward ports 80 and 443 for this. We're adding this port to manage our proxies.)
- Domain Names:
-
[service-name]:
- Domain Names:
[service-name].server1.lan
- Forward Hostname / IP:
server1.lan
- Forward Port:
[the port for this service]
- Domain Names:
-
Pi Hole:
-
server2
-
Nginx Proxy Manager
- Domain Names:
npm.server2.lan
- Forward Hostname / IP:
server2.lan
- Forward Port:
81
- Domain Names:
-
[service-name]
- Domain Names:
[service-name].server2.lan
- Forward Hostname / IP: server2.lan
- Forward Port:
[the port for this service]
- Domain Names:
-
Nginx Proxy Manager
-
server1:
After configuring your services, you should now be able to access your services via the subdomain from its respective server node. Try going to the Pi Hole admin console by entering pihole.[yourserver's hostname].lan/admin
. Works? Perfect!
It should also be noted that when entering one of these URLs, you must enter the forward slash at the end of the URL. So, pihole.server1.lan/
and not pihole.server1.lan
. I hope that makes sense.
Just remember: when adding services and you want to access them via subdomain, add the service name to the CNAME in Pi Hole, and then add the CNAME URL from Pi Hole to Nginx Proxy Manager.