Linux, Web Server & Database
Configure Nginx Virtual Host
Set up a correctly configured Nginx server block for your domain.
The Problem
Nginx is installed but your domain either shows the default page, the wrong site, or a 404 — because the server block (virtual host) for your specific domain isn't configured, or conflicts with another one already on the server.
About this problem
Nginx uses server blocks to decide which site to serve based on the requested domain name, and getting this wrong — a missing server_name directive, a root pointing at the wrong folder, or two server blocks both claiming default status — is one of the most common reasons a newly pointed domain doesn't show what's expected.
This comes up constantly when adding a new domain to a server that already hosts one or more other sites.
What's Included
- Creating a correctly configured server block for your specific domain
- Setting the right document root and index file handling
- Configuring PHP processing (if applicable) for that specific site
- Testing that the domain resolves to the correct content without affecting other sites on the server
What's NOT Included
- SSL certificate setup for the new domain (see the Let's Encrypt service)
- DNS configuration pointing the domain at this server (separate service if needed)
- Application-specific rewrite rules beyond standard setup (e.g. complex custom routing)
How It Works
- Create a new server block file under sites-available with the correct server_name and document root.
- Set up location blocks for static files and PHP processing as the application requires.
- Symlink the file into sites-enabled and check for conflicts with existing server blocks (particularly duplicate default_server flags).
- Test the configuration with nginx -t before reloading.
- Verify the domain serves the correct content and that other sites on the same server remain unaffected.
In practice: you buy the service, send over whatever access or details the job needs, I investigate and do the work, and you confirm it's resolved before we call it done.
Frequently Asked Questions
- Why does my new domain show the wrong website?
- Usually because another server block on the same server is catching the request first, either through a missing or duplicate server_name directive, or an existing default_server flag taking priority.
- What's a server block in Nginx?
- It's Nginx's term for what Apache calls a virtual host — a configuration section that defines how requests for a specific domain should be handled, including where to find its files.
- Can I host multiple websites on one Nginx server?
- Yes, that's exactly what server blocks are for — each domain gets its own block defining its document root and specific configuration, all served from the same Nginx instance.
- Why do I get a 404 error even though my files exist?
- Often the server block's root path doesn't match where your files actually are, or the location block handling that file type isn't configured correctly.
- Do I need a separate server block for www and non-www?
- It's common to have one canonical server block and a redirect from the other variant, rather than two full configurations serving the same content independently.
- How do I test my Nginx config without breaking the live site?
- nginx -t checks the configuration syntax without reloading anything, so you can catch errors before they ever affect the running server.