Point a Domain to Your VPS and Set the Web Root
This guide walks you through connecting a domain name to your virtual private server (VPS) and configuring the web server to serve files from a specific directory (the web root). By the end, typing your domain into a browser will display the website stored in that folder. You’ll need root or sudo access to your VPS and control over your domain’s DNS settings.
What You’ll Need
- A registered domain name (e.g., example.com)
- A VPS with a public IP address and SSH access
- Root or sudo privileges on the VPS
- Access to your domain registrar’s DNS management panel
- Basic familiarity with the command line
Step-by-Step
- Find your VPS IP address. Log into your VPS provider’s dashboard and note the public IPv4 address. It looks like
203.0.113.10. You’ll need this for DNS records. - Create an A record for your domain. Log into your domain registrar’s DNS settings. Locate the DNS management or “Advanced DNS” section. Add a new A record with the host field set to
@(or leave blank if your registrar uses that convention) and the value set to your VPS IP address. Save the record. - Create an A record for the ‘www’ subdomain. Add another A record with the host field set to
wwwand the value set to the same VPS IP address. This ensures that bothexample.comandwww.example.compoint to your server. - Wait for DNS propagation. DNS changes can take from a few minutes up to 48 hours to propagate globally. You can check progress using a tool like
dig example.comfrom your local machine or an online DNS checker. - Connect to your VPS via SSH. Open a terminal and run:
ssh user@203.0.113.10. Replaceuserwith your username (oftenrootor a sudo user). - Install a web server (if not already installed). For Nginx on Ubuntu/Debian:
sudo apt update && sudo apt install nginx. For Apache:sudo apt install apache2. For CentOS/RHEL:sudo yum install nginxorsudo yum install httpd. - Create the web root directory. Choose a path like
/var/www/example.com. Run:sudo mkdir -p /var/www/example.com. Set ownership to your user:sudo chown -R $USER:$USER /var/www/example.com. - Add a test file. Create
index.htmlin that directory:echo 'Hello World' > /var/www/example.com/index.html. - Configure the web server. Create a virtual host (Apache) or server block (Nginx) for your domain.
- Nginx: Create a file at
/etc/nginx/sites-available/example.comwith:server { listen 80; server_name example.com www.example.com; root /var/www/example.com; index index.html; }Then enable it:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/. - Apache: Create a file at
/etc/apache2/sites-available/example.com.confwith:<VirtualHost *:80> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com </VirtualHost>Then enable it:
sudo a2ensite example.com.conf.
- Nginx: Create a file at
- Test the configuration. For Nginx:
sudo nginx -t. For Apache:sudo apachectl configtest. Fix any syntax errors before proceeding. - Restart the web server. Nginx:
sudo systemctl restart nginx. Apache:sudo systemctl restart apache2(orhttpdon CentOS). - Adjust firewall (if enabled). Allow HTTP and HTTPS traffic:
sudo ufw allow 'Nginx Full'orsudo ufw allow 'Apache Full'. For firewalld:sudo firewall-cmd --permanent --add-service=httpand--add-service=https, then reload. - Verify in a browser. Visit
http://example.comandhttp://www.example.com. You should see “Hello World”. If not, wait a bit longer for DNS or check the troubleshooting section below.
Common Mistakes
- Using the wrong IP address – double-check that the A record points to the VPS IP, not the registrar’s or another server’s IP.
- Forgetting the ‘www’ record – without it, www.example.com won’t resolve.
- Incorrect file permissions – the web server user (e.g., www-data) must have read access to the web root. Use
sudo chmod -R 755 /var/www/example.comif needed. - Not enabling the site – in Apache, you must run
a2ensite; in Nginx, you must create the symlink. Otherwise the config is ignored. - Typo in server_name – a missing dot or wrong spelling will cause the domain to fall back to the default site.
- Firewall blocking port 80 – even if the server runs, external requests fail if the firewall doesn’t allow HTTP.
Tips
- Use a subdomain for testing – point
test.example.comto the VPS first to verify everything works before switching the main domain. - Set up SSL with Let’s Encrypt – after the site loads over HTTP, use
certbotto get a free TLS certificate. This is essential for modern websites. - Keep your web root organized – use a separate directory per domain (e.g.,
/var/www/example.com) to avoid conflicts. - Use a static IP – if your VPS provider gives you a dynamic IP, consider reserving a static one to prevent DNS records from breaking.
- Monitor DNS propagation – use online tools like whatsmydns.net to see if your A records have spread.
Troubleshooting
- Domain doesn’t resolve – run
dig example.comfrom your local machine. If it returns no answer, your DNS records are missing or propagation hasn’t finished. Check the registrar’s panel and wait. - Website shows default page – this usually means the server is running but your virtual host isn’t being used. Check that the config file is correctly named, the symlink exists (Nginx), and that the
server_namematches your domain exactly. - Connection refused – the server isn’t listening on port 80. Verify the web server service is active with
systemctl status nginx(or apache2). Also check the firewall. - 403 Forbidden – the web root directory or index file lacks proper permissions. Set
sudo chmod 755 /var/www/example.comand ensure the index file is readable. Also check that theindexdirective listsindex.html. - DNS works but site loads from a different IP – you may have an old A record cached. Flush your local DNS cache (on Windows:
ipconfig /flushdns; on macOS:sudo dscacheutil -flushcache). - After changing DNS, site still uses old server – wait longer. TTL values from your old records can delay propagation. You can lower TTL before making changes to speed up future updates.
Frequently Asked Questions
How long does DNS propagation take?
It can take from a few minutes up to 48 hours, though most changes propagate within a few hours. The exact time depends on your domain’s TTL and your ISP’s DNS servers.
Do I need to point both the root domain and www?
Yes, if you want both to work. Many users expect to type either. You can also create a redirect from one to the other, but having both A records is the simplest solution.
What is the default web root for Nginx on Ubuntu?
The default is /var/www/html. However, for a custom domain, it’s better to create a separate directory like /var/www/example.com to keep things organized.
Can I use a CNAME instead of an A record?
A CNAME can point a subdomain (like www) to another hostname, but the root domain usually requires an A record. For simplicity, use A records for both.
What if my VPS has IPv6 only?
If your VPS has only an IPv6 address, you’ll need to add an AAAA record instead of an A record. Most modern servers support both.
Do I need to install a database or PHP?
Only if your website requires them. For static HTML, a web server alone is sufficient. For dynamic sites, you’ll need to install PHP, MySQL, etc., and configure your virtual host accordingly.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.