How to Attach Domain Name to My Server

How to attach domain name to my server?

Just to explain, you have multiple things here:

  • Domain name
  • DNS nameservers
  • Web server(s)

All of these can be hosted with separate providers, but depending on your provider you might have different management options.

Domain name

Your domain name has a registrar (who you bought it from). That registrar will keep a list of 1-3 'nameservers' which are the addresses for the provider that hosts your DNS.

DNS nameservers

Your DNS is like your address book. That needs to be hosted somewhere, and if your old host didn't let you edit it, it's probably just part of their shared hosting service, and not something you can manage. You will need to change your domain name to point to another set of nameservers at a provider you can manage. Your VPS provider probably has a DNS service, but possibly not free (although many are). If needed you can use a free DNS host like XName or ClouDNS, but depending on your level of knowledge you might find these difficult to use.

A basic web server record you will want to add is known as an A record, and will point my-domain.com. and/or www.my-domain.com. (using a separate record) to your web server's IP address.

Web server

Your server has an IP address. If you need to load-balance for performance reasons you'll need your hosting company to provide you a 'virtual IP' or a load-balancer service, behind which you can have multiple servers.

Summary

The way the request goes is:

  1. User types my-domain.com into their browser
  2. The user's ISP's DNS server is queried for my-domain.com
  3. The web server IP address for my-domain.com is returned
  4. The user's browser sends a HTTP GET request to your server to get the web page

One part of the process leads onto the next, so you need to make the 3 things work in harmony to get your site to function.

How to link domain name with my VPS server

You will need to setup an A record in your DNS file which you should be able to do with the company that you have registered your domain with.
In their Control Panel somewhere the should be an option to add/modify your DNS entries.
To access your site as example.com you will need to set/change a record as such:

    Host = @ (or empty depending on the provider)
Type = A
IP Address = 25.100.12.xx

If you also want to allow access to your site via www.example.com you will need to add an additional record as follows:

    Host = www
Type = A
IP Address = 25.100.12.xx

If you then want to add any other addresses to go to the same IP Address you will need to do the same for them too.

How to assign a domain name to node.js server?

You do not assign a domain to a node.js server, instead you load your app onto a machine which has an ip adress, which in your case is 42.12.251.830:4000. You then need to make sure your app is listening on the correct port, which on most servers is 80

using express it's as simple as

var app = express()
, server = require('http').createServer(app)
, io = io.listen(server);

app.get('/', function(req, res) {
res.sendfile('./public/index.html');
});
server.listen(80);

Getting a domain name to point to this ip address is an entirely separate matter. You need to make your name server point to the ip. Your name server will usually be the company you bought the domain name through, for instance GoDaddy is a Domain Name Server (DNS). So if you had a domain name with them, you would go on their site under DNS settings and change the ip adress. Your domain name will then point to your ip adress and should render your node.js app.

create a domain name pointing to an IP of port different than 80

The domain company that you talked to may have done a poor job of explaining how domains work. Domain names don't refer to specific ports. They just refer to IP addresses. The client can look up a hostname to get the IP address which the client should connect to, but the client has to figure out the port without the help of DNS. Port 80 is just the default port for HTTP service.

You can certainly run a web server on port 8088 if you like. The port number would have to appear in the URL, e.g. http://somehost.example.com:8080/some/page. Clients would parse this and know to connect to port 8080 instead of the default port 80.

If you don't want URLs to contain the port number, then requests are going to go to the default port 80, and you have no choice but to make the web server running on port 80 handle these requests. HTTP/1.1 requests include the hostname which the client wants to contact, and modern web server programs are normally capable of serving completely different sets of content based on the hostname in the request. There are few ways todo what you need:

  1. Just configure the web server for port 80 to handle both sites. This will depend on what web server software you're using. Apache for example calls these "virtual hosts", and here is a set of examples. This is a typical solution, and some people run hundreds of sites on the same server this way.

  2. Run your two web servers as you planned. Set up the server for port 80 to be a reverse proxy for the second website. The server would continue to serve content for the site it handles now. When it receives a request for the second site, it would relay the request to the server running on port 8088, and relay the server's response back to the client.

  3. Move the existing server for port 80 to a different port. Run a pure reverse proxy server on port 80, relaying requests for both web sites to their respective web servers.

You might be better off taking further questions to https://webmasters.stackexchange.com/ or https://serverfault.com/.



Related Topics



Leave a reply



Submit