How to Connect Domain to Web Server?
How to Connect Domain to Web Server?

A lot of developers just know their part of project like only frontend or only backend but they don't know how to implement and deploy project fully to the production. And the important part of it is connecting your domain to your webserver.

How web is working?

This knowledge actually goes in the direction how web is working and it a question that you can hear on the interviews quite often.

What happens when you type google.com in the url?

You must know that the web works by using DNS. DNS (domain name system) is something similar to the table with key and value. The key is our domain (for example google.com) and value is an IP address of the server where our request must go.

DNS

So person jumps to google.com because of DNS which sent the request to our server that we rented and configured.

What registrator to use?

Now you probably want to buy a domain for your new project and you are wondering where you should buy it? Typically you buy a domain from the registrator and we have lots of different companies which sell domains. The most popular are GoDaddy, Google domains and Bluehost but there are hundreds of other registrators.

It doesn't really matter what company you will choose. They are all doing the same thing. They just sell you domains and transfer all requests from your domain to your IP address. Typically they have additional stuff but this are the basics which are the same everywhere.

Here I want to show you what registrator I use myself. And this is not the advertisement but just a good place to store domains. I use Google Domains which is the registrator by Google. And obviously you can understand that it is a huge company and you will have good support and lot's of guides how to configure things.

Another important point for me was that Google Domains don't have any advertisement. Typically in other registrators you have lot's of advertisements about low prices, some domains with random names with 30% discount and lot's of stuff that you don't need.

ADS

Google Domains is the first provider in my experience which doesn't have any advertisement. Here you just see prices for a year and this is it. .com domain costs 12$ and it is crystal clear. There are no additional costs.

In my previous provider the price for domain was floating and I paid a random amount every year.

How to rent a domain.

In any registrator you can search for domain name. And you must understand that it is not bounded to registrator. You can rent the same name by any provider. So you just check if domain is free than you pay for it and you are good to go.

After buying you will see a page with access to configuration of your domain. The next important step here is to bind this domain to your server that you rented. Which means you must rent a server and run there a webserver which will serve your project.

Now we need to provide a server IP address for our domain in configuration section. We must create A type record like I did here. And we do it for both with www and without www cases.

ADS

80 port

But it is important to understand that the web works by transfering your domain request to 80 port. So if you time google.com it will send you to the IP address like 111.111.11.11:80 so it's not just an IP address but also an 80 port. It is not visible in browser but this is how it works.

If you just testing something you can access your IP address and any port directly inside a browser.

So your server must be prepared to get a request from your domain on 80 port. And the most common practice is to use Nginx package for this.

Nginx is a reverse proxy, web server and load balancer

Inside you can specify what to do with your request.

Debugging without buying

But sometime you want to debug how your project will work on real domain without buying a domain just locally. For this you can use hosts. It's a special file where you can specify which domain should hit what address. It will look like this

113.203.192.254 eltrello.com
127.0.0.1 realworld-docker.local

So instead of asking registrator and global DNS this url will be resolved by your computer. It is a nice way to point your local project to localhost but use a real domain instead.

Also if you are interested to know how web is working from start to the end make sure to check this post also.