0

Setup:

I have various devices on my home network. I have used ".home" as the domain for this network. My router (ASUS - with Merlin firmware) supports basic DNS and can route "desktop.home" to the appropriate device within the network. I have a domain name "reallyreallyreallycoolname.com" which has a subdomain that points to my home network (*.home.reallyreallyreallycoolname.com).

Problem:

I want NGINX to remove the domain name from requests and send the request on to the appropriate destination based on the router's DNS table. So a request for desktop.home.reallyreallyreallycoolname.com will be sent via reverse proxy to 192.168.1.81 (or whatever IP is assigned to "desktop.home").

Attempted Solution:

I was thinking that for "server name" there could be a capture group and proxy_pass would restate it. For example:

server_name {*}.home.reallyreallyreallycoolname.com; location\{ proxy_pass http://{\1}.home }

1 Answers1

0

I somewhat figured it out. Server names can include variables captured using Pearl Compatible Regular Expressions as described here. The code for my example is:

...
server_name ~^(?<hostName1>.+)\.home\.reallyreallyreallycoolname\.com$;
location/{
   proxy_pass http://$hostName1.home;
}
...

However, although the variable name captures correctly and nginx interprets "http://$hostName1.home" as it should, it fails to resolve. My guess is NGINX performs DNS resolutions happen when it starts and not at runtime.

Update

Following How to force nginx to resolve DNS (of a dynamic hostname) everytime when doing proxy_pass?, it turns out you have to specify a DNS resolver for the server so that it will know how to resolve the call.