I recently installed apache2 on my raspberry pi 4B. I can reach it from the local IP (192.168.1.85). FYI I used this tutorial. Anyway anywhere 'example.com' showed up I entered an UNUSED domain name, which we'll call mydomain.com (sorry I couldn't show you the real domain). Anyway, it still gives me a 404 error (even on port 80), the default I set. There's probably something I'm doing terribly wrong, but I find DNS and apache confusing, so if you could help me that'd be great.
That it is always a 404 is a bit odd, unless by coincidence this domain name is an existing one and you are accidentally connecting to an external server.
we'll call mydomain.com (sorry I couldn't show you the real domain)
If this is an actual domain name that you have registered, you will need to set the name server you are using to point to the correct IP. A
192.168.x.x address is not valid for that.
Since you don't refer to any of this, I'm assuming it isn't registered and you were just hoping the domain would work (perhaps because you put it in an apache configuration). That's not how it works.
I won't regurgitate how DNS resolution works since this is very well documented many places online already. What you can do, if you want to use the domain name locally in development (sometimes this is significant), is add to the
localhost entries in
127.0.0.1 localhost foo.bar ::1 localhost ip6-localhost ip6-loopback foo.bar
When you try to connect to
foo.bar from the Pi, you will now be connecting to the Pi (local loopback). This will not work from another machine regardless of where it is unless you similarly spoof the DNS settings there.
Note this is not the same as setting the global
hostname, which will remain unchanged.
Unless you have a domain name registered and an A record pointing to the IP address of the Raspberry Pi, you have to use an IP address to connect to your Pi's webserver.
Also, your Pi's IP address
192.168.1.85 is not globally accessible - it can only be reached from your own LAN.
Assuming you are running Raspberry Pi Os Buster, your Pi is running
avahi-daemon which means it is advertising its own hostname to your LAN on the
.local pseudo domain.
hostname to find out your Pi's hostname.
Then, from another computer, try
ping -n raspberrypi.local
(raspberrypi is the default hostname; substitute your Pi's actual hostname for raspberrypi).