Pointing a domain at your VPS

A step-by-step guide to connecting a domain to a virtual server; from setting up the A record in DNS to configuring the web server and issuing an SSL certificate. With practical examples and troubleshooting.

6 min Updated 9 Sep 2026

Why Does Connecting a Domain to a Virtual Server Seem Complicated?

When you purchase a virtual server (VPS), you get a public and dedicated IP address. But your users access your site via a domain name, not an IP. Connecting a domain to a server means establishing a bridge between the two: the domain name must point to your server's IP, the web server must accept requests for that domain, and finally, a secure HTTPS connection must be established. In this article, we will walk through this exact path step by step; no fluff, just real-world examples.

Many users think connecting a domain to a server is just a simple DNS panel setting. But if the web server (Apache or Nginx) is not configured for your domain, you will encounter a Domain is not configured error or the server's default page. In the following sections, we cover all three layers: DNS, web server, and SSL.

Step One: Setting Up the A Record in DNS to Connect the Domain to the Server

The A record (Address Record) is the simplest and most important type of DNS record that maps a domain name to an IPv4 address. To connect your domain to the server, you need to create this record in your domain's DNS service (usually managed by your registrar or domain host).

Accessing the DNS Management Panel

Depending on where you bought your domain, the access path may differ. Usually, in the user panel, there is a section called DNS Management, Zone Editor, or Manage DNS. If your domain is on another company's nameservers, you must use that panel.

Creating A Records for the Main Domain and the www Subdomain

Create two separate A records:

  1. Main domain (e.g., example.com): In the Name or Host field, enter @ or leave it blank (depending on the panel). Set the Value or Points to field to your server's IP.
  2. www subdomain (e.g., www.example.com): In the Name field, enter www and put the same IP in the Value field.

A real-world example of an A record in a zone file:

example.com.  3600  IN  A  185.10.20.30
www.example.com.  3600  IN  A  185.10.20.30

The number 3600 is the TTL (Time To Live) value, in seconds. That means one hour. If you are testing, you can lower the TTL to 300 (5 minutes) so changes propagate faster.

Checking DNS Propagation

After saving the records, propagation across DNS servers worldwide can take anywhere from a few minutes to 24 hours. To check quickly, use the following command in your terminal:

dig example.com A +short
dig www.example.com A +short

The output should show your server's IP. You can also use online tools like dnschecker.org.

Common mistake: Many users only set the A record for @ and forget the www record. Result: when users visit via www, they get a DNS error. Always create both records, or at least create a CNAME record for www pointing to the main domain.

Step Two: Configuring the Web Server to Accept the Domain

Now that DNS points to your server's IP, you need to configure the web server (Apache or Nginx) to handle requests for your domain. Otherwise, the browser will show the default page or a 404 error.

Nginx Configuration (Practical Example)

Assume you are using Nginx and your domain is example.com. First, create a new config file in the /etc/nginx/sites-available/ directory:

sudo nano /etc/nginx/sites-available/example.com

Enter the following content:

server {
    listen 80;
    server_name example.com www.example.com;

    root /var/www/example.com;
    index index.html index.php;

    location / {
        try_files $uri $uri/ =404;
    }
}

Then create a symbolic link to the sites-enabled directory and test the configuration:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

If you are using PHP-FPM, also add the location ~ \.php$ block.

Apache Configuration (Practical Example)

For Apache, create a VirtualHost in the /etc/apache2/sites-available/ directory:

sudo nano /etc/apache2/sites-available/example.com.conf

Suggested content:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com

    <Directory /var/www/example.com>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Then enable the site and restart the service:

sudo a2ensite example.com.conf
sudo systemctl restart apache2

Testing the Domain-to-Server Connection

After configuration, open http://example.com in your browser. If you see the contents of the /var/www/example.com directory, the domain-to-server connection has been successfully established. If you see a 403 or 404 error, make sure the index.html file exists in the root directory and that permissions are correct.

Troubleshooting tip: If you still see the default Nginx or Apache page after setting up DNS and the web server, your domain configuration is probably not loaded. Use the command sudo nginx -T | grep server_name (for Nginx) to verify that your domain appears in the list of server_name entries.

Step Three: Issuing an SSL Certificate for a Secure Connection

Once the domain-to-server connection is established, it's time for HTTPS. Today, an SSL certificate is essential not only for security but also for SEO and user trust. The easiest way is to use Let's Encrypt and the Certbot tool.

Installing Certbot and Issuing the Certificate

First, install Certbot (example for Ubuntu/Debian):

sudo apt update
sudo apt install certbot python3-certbot-nginx

Then run the following command for Nginx:

sudo certbot --nginx -d example.com -d www.example.com

For Apache:

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com

Certbot will automatically issue the certificate, update the web server configuration for HTTPS, and enable HTTP to HTTPS redirects. After running it, test the address https://example.com.

Changing DNS Records After SSL

An important note: if you are using direct A records, no changes are needed after SSL. However, if you are using a CDN or Reverse Proxy, you must ensure the certificate is issued for the main domain and that SSL settings are enabled in the CDN.

Automatic Certificate Renewal

Let's Encrypt certificates are valid for 90 days. For automatic renewal, a systemd timer is installed by default. You can check it with the following command:

sudo systemctl list-timers | grep certbot

If the timer is not active, add a cron job:

0 3 * * * /usr/bin/certbot renew --quiet
Common mistake: Some users change the A record or move the domain to another server after issuing SSL but do not renew the certificate. Result: a SSL certificate mismatch error or a security warning in the browser. Always re-issue the certificate after changing the IP or server.

Summary and Final Checklist

Connecting a domain to a virtual server involves three distinct layers, each of which must be done correctly:

  • DNS: The A record for the main domain and www must point to the server's IP.
  • Web server: A VirtualHost or Server Block must be defined for your domain.
  • SSL: A valid certificate must be issued and HTTPS redirect enabled.

If you follow all three steps in order, your domain-to-server connection will be stable and secure. Finally, if your virtual server is hosted in Iran and you need technical support, ServerNet can help you with initial setup and troubleshooting DNS and web server issues; however, you can also perform all the steps in this article independently.

I suggest saving this checklist and reviewing it again after any changes to DNS or the server. Although connecting a domain to a server may seem multi-step at first glance, with this guide it can be done in under 30 minutes.

Was this page helpful?