After you have deployed a website online, it's time to choose its custom domain name: initially, the hosting provider assigns you a random subdomain name like "blog-xk7r.yourprovidername.com". However, who wants their nicely built website to be called like that? But what is a domain name? And how does your (or anyone else) computer's web browser finds the correct website the first time someone tries to visit it?
To start with, computers do not use "names" to communicate with each other as humans do: they use numbers or better IP addresses. Therefore, if for example, I want to visit the page www.google.com, everything my computer needs to know is its "local" IP address (something like 142.250.191.78, which is still an IPv4, but due to the growing number of devices that are connecting to the web, the IPv6 are already in use and becoming more and more common): you can try to copy and paste it on the address bar and you'll see that you are going to reach it as well.
However, we will never remember hundreds or thousands of numbers which don't mean much to us: therefore, networking engineers came up with a system called DNS, Domain Name System, which resolves every domain name into an IP address and communicates it to your computer. Basically, a DNS works as one of those old phone books (for those old enough to remember them...🥲) where you would search for a name and find its telephone number.
Therefore, to come back to the previous example, when you type an address in your browser, the computer (after having verified the corresponding IP address is not already saved in its cache) queries a DNS server to resolve the domain name to an IP address. The DNS server finds the matching IP address and returns it to your computer, which can then connect to the web server hosting the website. The IP address is then stored in your computer's cache to avoid querying the DNS server again for the same domain in the future. Once the connection is made, the browser retrieves the website content, and you see the webpage.
Ok, so now that you know what is a domain name and have chosen yours, you can apply it to your website and are ready to go, aren't you? Well...no: you have before to check if it is still available, but above all you have to "rent" and pay for it (💸... )from a domain name registrar. There are many to choose from, but I advise you to pick it carefully because not all of them are trustworthy and "reliable" and I have read very nasty stories on the web...anyway, I have chosen Porkbun and so far, so good. On top of that, you have to configure the DNS.
Once the domain name has been chosen and registered, you can configure it to point to your website: on Render (the hosting provider on which I have chosen to deploy my blog), open the settings of your web service, scroll down till the "Custom Domains" field and click on "+ Add Custom Domain". Two versions (www.your_domain_name.com and your_domain_name.com) of your domain name will appear and next to them the instructions to configure the DNS. There is also a button to copy the subdomain name, which you will need later for the configuration.
Now, returning to Porkbun page, click on "ACCOUNT" on the top right corner and then on "Domain Management". After that, click on "Details" on the left of the screen to make appear a large dropdown menu and click on the little pencil next to the "DNS RECORD" option: now you have to configure both versions of your domain name, because while the "www" version requires a CNAME ("Canonical Name", which points to another domain like www
to the root domain) type, that without requires an A or (if not available) an ALIAS (which points to an IP address) one. Instead, for both address configurations, paste the subdomain name in the field "Answer".
IMPORTANT: do not forget to update your repository and push it to the remote branch to be accessible by the hosting provider! Therefore, open your local version of your project on Vscode (or your favourite code editor), go into your main app.settings.py file and add to the list of ALLOWED_HOSTS your:
Just to give you a bit more context, ALLOWED_HOSTS
is a security feature in Django that prevents HTTP Host header attacks, allowing only the secure and authorized domains.
Finally, we can go back to Render, click on "Verify" and after a couple of minutes you should see next to each version of your address two green boxes with the confirmation that the address is "Verified" and "Certificate issued". If you’ve done everything correctly, congratulations! 🎉 You can now visit your webpage using your custom domain.
Keep following me: the journey continues...
(PS: This is an AI cruelty-free post, meaning that no AIs have been exploited to write it.)
Posted on: 19 Oct 2024, 7:09 p.m.
(Login to like/comment)
Cool topic!