Tutorial | Traffic Routing, Domains, and DNS

by allsparkinfinite on 2025-02-15

Step 1: Setting Up A Test Server

If you already have a server running, you can skip this step.
If you have no server running, you can bring up a test server, just to work with for this tutorial. The simplest kind of server just shows you all the files in a directory. If you have python installed, you can run such a server with sudo python3 -m http.server 80. If you are working with a web server, such as Apache or NGINX, you will have to write a configuration file.
For NGINX running on Linux, you would add a configuration file in /etc/nginx/sites-enabled. The above directory can only be edited by the admin, known in Unix-like systems as a "superuser", so you will need to edit it with a terminal text editor. Nano is a popular one, and to create a file named test in the above directory, you would run sudo nano /etc/nginx/sites-enabled/test. Write the following in the file:

server {
    root /home/username;
    autoindex on;
}

replacing username with your username in the computer. Then, restart the NGINX server with sudo systemctl restart nginx.

Step 2: Ensuring The Server Is Active

If you have a web browser on the same computer where the web server is running, you should be able to access the server at http://localhost:80. If your server is running on a different port, you will need to place that number after the colon instead of 80. If you do not mention a port number, http defaults to 80 and https defaults to 443.

If your web browser is on a different computer that is connected to the same local network, like the same wifi or wired internet in the same setup, you should replace "localhost" with the local IP address of the server computer. Running ifconfig should show you the IP address of the computer.

If your web browser is on a cloud computing service, like I do with Oracle Cloud, you should be able to type in the same IP address into the browser that you use for SSH connections.

Step 3: Accessing It Through The Internet

Method 1: Port Forwarding

This requires a few things - your ISP needs to provide you with a dedicated public IP, and is forwarding incoming connections on all (or, at least, user-defined) ports to your connection. This is often only provided on a business connection, not on residential connections. If you have a router between your ISP and your server hardware, you would also need to set up port forwarding on the router.
You will need to find other tutorials for this because I have not been able to set this up.

Method 2: Localhost Tunnel

A localhost tunnel is the connection between two computers, one of which is publicly addressable (frontend) and the other isn't (backend). Since one cannot initiate a connection to a computer that isn't publicly addressable, the backend takes up the job of setting up a "heartbeat" connection to the frontend. If there are any requests from a browser to the frontend, it will forward that information to the backend on the next heartbeat.
The frontend can be managed by services like Cloudflare or Pagekite, or can be set up on a cloud computing service with a tunnel like Rathole.

Step 4: Using Wordy URLs

If you look at the address https://blog.allsparkinfinite.name/auth/login, https:// is the protocol/scheme, /auth/login is the path, and the middle bit is the domain. The domain is split up by full stops. The last segment is called the Top Level Domain, the last two segments taken together are called a domain name, and the remainder (if any) is called a subdomain. You can get subdomains for free at FreeDNS, or you can rent a domain at a domain registry like Namecheap.
You will then have to configure DNS records to point a subdomain to an IP address (A Record, if you have a public IP) or to another domain name (CNAME Record, if your localhost tunnel gives you a target domain)