With many geeks trying to self-host their own servers lately, I see some confusion about how all that stuff work, and what should you do to host a web blog and a gemini capsule on the same server on the same domain name.
Here’s my humble attempt to explain, as simple as possible, what’s going on when someone makes a request to an internet resource.
Each internet resource (web server, mail server, file server, chat server, etc) has a unique reference called URL. That’s how we locate different resources on the net. URL includes, among others, protocol, host name, and port of the resource.
Client machine queries its DNS server where the target domain name is located, in internet terms. DNS server returns an IP address which is associated with the requested domain name.
Client machine builds path to the IP address through multiple nodes using network routing. As the desired IP address is reached, client software tries to establish a connection on a specific port of the target machine.
Every internet protocol has a designated port, the one used by default if no particular port specified in the URL. Say, designated port for FTP is 21, for SSH – 22, for SMTP – 25, for HTTP – 80, for HTTPS – 443, and so on. Gemini protocol has a designated port 1965 (by the year of the first manned Gemini mission flight), thus a request to URI gemini://themactep.com will try to open a connection on port 1965 of a server with the IP address 18.104.22.168.
But what if there are multiple servers with the same protocol hosted on the same machine? Or if the server is set up to listen on a non-standard port? How do we reach it then? In that case you need to add the specific port to your URL, like this http://themactep.com:9999 which is equal to http://22.214.171.124:9999 in this particular case.
Why the particular case? Because some servers can host not only multiple services for the same domain name, but multiple domain names on the same internet server. E.g. web servers like Apache and NGINX can determine what exact virtual host was contacted on the same IP address and the same port by the domain name used in the request. That makes requests to two different URLs, http://themactep.com/ and http://paulphilippov.com/, connecting the same port 80 on the same IP address 126.96.36.199, but resulting in different contents.
I hope this short article makes all that internet sorcery a little bit less magical. If you still have questions, don’t hesitate to ask in comments.