andygc
Posts: 5
Joined: Thu Sep 28, 2017 3:33 pm

Accessing a subdomain on a local Pi web server

Sun Feb 16, 2020 10:38 am

Good morning

I'm using a Pi as a web server on my home network for WordPress site development. The current project is to add a subdomain to the main website so that a shop runs as a separate site - running a different theme because the parent site's theme doesn't have the right look and feel for a shop.

I have created the subdomain on the Pi and can access it using the browser on the PI - http://shop.webpi

I have no problem accessing the server from a Windows 10 computer on the local network using the Pi's hostname - http:/webpi or just webpi - but I cannot access the subdomain - http://shop/webpi - Firefox gives me "We can’t connect to the server at www.shop.webpi."

I'm not using a fixed IP address for the Pi. Is there a way of making the subdomain discoverable without having to use a fixed IP address and then editing hosts files on any machine I want to access the development site from?

Thank you for your help.

epoch1970
Posts: 4492
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Accessing a subdomain on a local Pi web server

Sun Feb 16, 2020 1:58 pm

Add a DNS server to your LAN, configure it, and you won’t need to edit the hosts file on individual machines.
Dnsmasq is a good candidate for this task.

Once it is setup, make sure LAN clients do query the new DNS server (and not, say 8.8.8.8). You’d do that by changing the configuration of your DHCP server.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

biobuntu
Posts: 5
Joined: Wed Jan 31, 2018 4:49 am

Re: Accessing a subdomain on a local Pi web server

Sat Feb 22, 2020 4:41 pm

Other method

you need to edit your /etc/hosts on the server
and add 127.0.1.1 name of your domaine here (on the server)
add this in your client /etc/hosts :
192.168.... (your rpi server) nameOftheRpiServerDomainHere

i hope its helpfull
other tricks on my blog if you are interested (french)
https://pointbat.wordpress.com

Have fun !

andygc
Posts: 5
Joined: Thu Sep 28, 2017 3:33 pm

Re: Accessing a subdomain on a local Pi web server

Thu Feb 27, 2020 7:27 am

Thank you, but you seem to have missed the point.

I already have the subdomain working correctly when browsing locally on the Pi itself - I already have it defined in the hosts file. I thought I had also made it clear what I wanted to achieve, if it is possible.
I'm not using a fixed IP address for the Pi. Is there a way of making the subdomain discoverable without having to use a fixed IP address and then editing hosts files on any machine I want to access the development site from?
What I did not add is that I plug the Pi into another network to show people how the website development is progressing. I cannot alter that network's configuration, so adding a local DNS server is not possible.

I want to be able to plug the Pi into a network and then to access its web pages using http://webpi and http://shop.webpi without having to reconfigure the network and without having to use a fixed IP address - the networks don't use the same netmask.

If the answer is "it can't be done", then that's fine. I'll have to use two Pi servers, one for the primary domain and one for the subdomain.

epoch1970
Posts: 4492
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Accessing a subdomain on a local Pi web server

Thu Feb 27, 2020 4:20 pm

No static hosts and no DNS servers... mDNS maybe?

If your Pi is called webpi you can find it on zeroconf/mDNS capable machines (macs, most linuxes, some windows) under webpi.local.
"ping webpi.local" or "http ://webpi.local/foo/" should work.

Publishing a CNAME is a bit tricky. Assuming the Pi's IP address on the local network is 172.17.255.55/16, the following: "avahi-publish -R -a shop.webpi.local 172.17.255.55/16 &" (-R is important) should make "http ://shop.webpi.local" work the same as "http ://webpi.local".
Launch avahi-publish from a script that fetches the current IP address. The record is not dynamic, if the address changes the script should kill the avahi-publish process and relaunch a new instance. Avahi-publish is part of package avahi-utils.

Publishing an HTTP service is complicated. The "bonjour tab" was removed from most browsers for security reasons ages ago and apparently Apple is fine with that. There is at least one brave soul that made a host extension + browser extension that you can install on machines where you want to reinstate the old "bonjour tab" (works in FF and Chrome, AFAIK).
IIRC avahi-publish doesn't handle txt records; Via command line you can publish an http service name, port but not its path, e.g. "/shop/". To do that you can declare a static service record in /etc/avahi/services. Static records live as long as avahi-daemon lives. Not as long as your web server lives.

Publishing an HTTPS service is out of the question. By design, web browsers do not support the _https._tcp service type. If you want to publish an https server you need to publish the url to an http redirector instead.

That's all I have. I think bringing your own network (a VLAN or wifi) and telling people to use that would probably be easier.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

andygc
Posts: 5
Joined: Thu Sep 28, 2017 3:33 pm

Re: Accessing a subdomain on a local Pi web server

Thu Feb 27, 2020 5:19 pm

Thank you

Yes, I have no problem finding http://webpi on my network, with or without "local" and with or without "http://" (using Firefox). I'll have a look at avahi as you suggest and see how I get on.

Thanks, Andy

epoch1970
Posts: 4492
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Accessing a subdomain on a local Pi web server

Thu Feb 27, 2020 5:50 pm

mDNS works on any local network, but only for ".local" names. "webpi" will never resolve via mDNS. "webpi.local" always will.
On your network resolution of the machine's unqualified name might be helped by a DNS server or even by NETBIOS.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “General discussion”