Add domain to VPS (DNS?)

5,937

To get a website up at a domain name you need to follow these steps:

  1. Register the domain name.
  2. At the registrar, point the NameServer (NS) records to the domain name server (DNS) that will be handling the domain.
  3. On the name server, add records to resolve the host name to your server.
  4. Configure your web server to handle requests that come in for that domain name.

I never run my own name server. Third party name server service is dirt cheap and much more reliable. I wouldn't pay more than $10 per year for it. You really should have three or four name servers running in different locations for redundancy and reliability. It sounds like your web host has name servers for you to use and I would take advantage of that.

The DNS records on the name server can be either A records that list the IP address of your web server, or CNAME records pointing to another host name that you have already set up to point to your server. Your web host has a way for you to add these records. It is usually a web interface they give you in a control panel where you can create these records.

On Ubuntu, the recommend way to add Apache configuration for a website (substitute example.com for your actual domain name) is:

  1. Create a directory for the files to be served /var/www/example.com and put the HTML files there.
  2. Create /etc/apache2/sites-available/example.com.conf:

    <VirtualHost *:80>
        Servername example.com
        DocumentRoot /var/www/example.com
        <Directory /var/www/example.com/>
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    
  3. Enable the site: sudo a2ensite example.com
  4. Restart the webserver: sudo service apache2 restart
Share:
5,937

Related videos on Youtube

Rafcio Kowalsky
Author by

Rafcio Kowalsky

Updated on September 18, 2022

Comments

  • Rafcio Kowalsky
    Rafcio Kowalsky over 1 year

    I have a VPS and some domains. I want to add one of my domains to the VPS.

    My VPS provider has send me his Nameservers like ns1.example.com and ns2.example.com and I changed these DNS records in my domain panel.

    Should I now install a DNS server on my VPS, add a record to Apache configuration file, or edit hosts file?

    The OS is Ubuntu with Apache btw.

    What exactly should I do?

    • Cristian Bica
      Cristian Bica over 9 years
      What do you mean by "add domains to the VPS"? Do you just want to point the domains to the IP of the VPS, or..? You don't need to install a DNS server.
  • cnayak
    cnayak over 9 years
    How does this answer the question?