When a website works by IP not domain, your server is running, and the fault sits between the domain name and the machine. Either DNS sends the domain to the wrong IP address, or your web server doesn’t recognise the name when the request arrives.
Each cause needs a different repair, so a few quick tests come before any config edit. At Basic Linux, we often see IP-only access catch out new server owners after a migration or a fresh install.
The steps below start with terminal checks for Linux DNS troubleshooting, then move to the Apache and Nginx settings that decide which site answers. We finish with a table that pairs each failed test with the matching repair.
Why Does a Website Work by IP but Not Domain?

Two separate systems handle IP requests and domain requests. Typing the IP address skips the name lookup, so your browser talks straight to the server. A domain name has to pass through the Domain Name System (DNS) first, and any fault on that path stops the request early.
Each DNS lookup runs through several layers of nameservers, from the root down to your domain’s own servers. The lookup can stall at nameservers left over from a domain transfer or at an A record pointing to an old host. A cached answer causes the same failure until its TTL runs out. A lapsed domain registration can break every lookup, because the registry may stop publishing your nameservers.
DNS can also resolve correctly while a second fault hides on the server. Your browser sends the domain in each request’s Host header, and the web server reads the header to pick a site. A request sent to the bare IP carries the IP in its Host header, so no name matches and the server hands it to the default site. When your site is the default, the IP loads correctly. If another block lists your domain (often a leftover from an old setup), requests for the name land there instead.
If you’ve just moved from shared hosting to a VPS, the domain may still point to your old account. The same goes after leaving managed or WordPress hosting, where the provider handled DNS for you.
Linux DNS Troubleshooting Checks for VPS and Cloud Servers
Once DNS becomes the first suspect, the terminal gives you cleaner answers than a browser. Browsers cache old lookups, while command-line tools query DNS directly and show the raw result.
Start by comparing what your machine sees with what a public resolver reports. If dig returns an address that differs from your server’s IP, the fault lies in your DNS records. We’ve watched people spend an afternoon rewriting Nginx configs while the A record still pointed at their previous provider.
Your local /etc/hosts file can also override DNS on that one machine. A forgotten test entry there makes the domain load for you and fail for everyone else (or the reverse, which is far harder to spot). And if you’re testing from home on the NBN, your router may hand out its own cached answers too.
Run these checks in order and note which one gives an unexpected answer. That first odd result tells you which layer to fix.
- Local Lookup:
dig short yourdomain.com Ashows the IP your resolver returns. It should match the IP that loads your site. - Public Resolver:
dig @8.8.8.8 yourdomain.comasks Google’s public resolver instead. A different answer means one cache still holds an old record. - Nameservers:
dig NS yourdomain.comlists the nameservers for your domain. They must match the DNS host where you edited your records. - Hosts File:
grep yourdomain /etc/hostsfinds any local overrides. Delete old test lines it returns, then check again. - Server Response:
curl -I http://yourdomain.comshows the headers your server sends back. Look at the status code and the Server line.
If every lookup returns your server’s IP and curl still misbehaves, rule out DNS and move on to the web server config. That’s where name matching happens.

Web Server Configuration: Fixing Apache Virtual Host and Nginx Server Name Problems
When DNS checks out but the website works by IP, not domain, the search shifts onto your server. Apache and Nginx read the requested domain from each request’s Host header, compare it against their config files and pick the site block that matches. Our guide to diagnosing common Linux web server problems covers wider faults, but name matching is where this symptom usually starts.
The four fixes below run in the order you’d apply them. Two handle name matching, one handles certificates, and the last keeps your reload safe.
Setting ServerName and ServerAlias in an Apache Virtual Host
Apache picks a virtual host by comparing the Host header against each block’s ServerName and ServerAlias. The Apache name-based virtual host documentation confirms Apache uses the first listed virtual host for that IP and port when nothing matches.
The fallback explains why an Apache virtual host domain issue can show another site’s page. Add ServerName yourdomain.com and ServerAlias www.yourdomain.com inside the correct block.
After saving, run apachectl -S to list every virtual host and the file that defines each one. Make sure your domain appears next to the right config file before you reload.
Setting server_name in Nginx
Nginx sends a request to the default_server block when no server_name line matches the incoming domain. The Nginx guide to how requests are processed confirms the default server handles any request whose Host header matches no name.
If no block carries default_server, Nginx treats the first server block for that port as the default. A typo like exmaple.com sends every visitor for your domain to the first block instead. The result can look like an Nginx domain not resolving, even though DNS works. Visitors usually land on the stock welcome page that ships with Nginx.
Open your site file in /etc/nginx/sites-available/ and list both the bare and www names on the server_name line. Next, confirm a symlink exists in sites-enabled, because Nginx ignores files without one. On RHEL-based systems, site files usually sit in /etc/nginx/conf.d/ instead.
Checking Your SSL Certificate Covers Each Hostname
A certificate that lists the wrong name makes a working domain look broken. Browsers check that the certificate covers the exact hostname typed and block the page with a warning on a mismatch. SSL certificates are digital certificates tied to specific hostnames, so each version of your domain needs its own entry.
The mismatch tends to appear after you add www to a site whose certificate only lists the bare domain. HTTPS visitors on www then see a warning, while the bare domain and the IP over plain HTTP still load.
Run openssl s_client -connect yourdomain.com:443 -servername yourdomain.com and read the subject alternative names. If your hostname is missing, reissue the certificate with certbot --nginx -d yourdomain.com -d www.yourdomain.com. Swap --nginx for --apache if Apache serves the site.
Testing the Config and Reloading Without Downtime
Test every change before you reload. With a syntax error, a reload keeps the old config running, but the next restart or reboot will fail and take your sites offline. Use apachectl configtest for Apache or nginx -t for Nginx, and correct anything they flag.
Once the test passes, run systemctl reload apache2 or systemctl reload nginx. On RHEL-based systems, the Apache service is called httpd. A reload applies the new config while existing connections finish, so visitors don’t see an outage.
In our experience, untested configs cause most of the downtime we see after small name changes. Chaining the test and reload as nginx -t && systemctl reload nginx stops the reload whenever the test fails. Most Linux admin best practices put the test before every reload for the same reason.
Match Each Failed Test to Its Fix
Running the checks in order narrows the search one step at a time. Find your first failed result in the table below, then apply the matching step.
| Test that fails | What it tells you | What to do |
|---|---|---|
dig returns the wrong IP |
The A record points elsewhere | Update the A record at your DNS host and wait for the TTL to expire |
dig NS shows old nameservers |
The registrar still points at your previous provider | Change the nameservers at your registrar |
curl with your Host header returns a default page |
The server matched the domain to the wrong block | Add ServerName or server_name, then test and reload |
| Browser shows a certificate warning | The certificate misses this hostname | Reissue it with every hostname listed |
curl returns 403 Forbidden |
The server can’t read your site files | Check ownership and permissions on the web root |
A 403 on the domain alone usually means its site block points to a different web root than the default site. Check that the web server user, such as www-data, can read every folder in that path. On Nginx, a missing index file in the web root returns the same 403.

Get Your Domain Pointing at the Right Server Today
Start with dig and confirm the A record and nameservers point to your server. If your hosting provider manages DNS, ask them to check the A record first. Next, test the server directly with curl and your domain in the Host header. Change only the part that fails, and run a config test before every reload.
Basic Linux writes plain-English guides for people who run their own Linux servers on VPS or cloud hosting. Contact our team with your setup details, and we’ll help you find where the request breaks.