Skip to main content
This lesson walks through creating a minimal “Hello World” website served by NGINX on a single host. Follow these steps in order:
  • Verify NGINX is running.
  • Create a simple server block in sites-available.
  • Create the document root and index.html.
  • Enable the site and test it locally using the Host header.

1. Verify NGINX is running

Check the service status and start it if necessary:
Confirm the default page is served:
Example returned HTML (truncated):
This verifies that NGINX is installed and serving the default page.

2. Become root and inspect NGINX configuration directories

To avoid prefixing sudo for each command, switch to root for the remainder of the setup (optional but convenient):
You should see sites-available/ and sites-enabled/ among the configuration files. Then change into sites-available:
Typically you’ll see a default file here.

3. Create a new site configuration

Copy the default site config to a new file named helloworld:
Edit helloworld and simplify it to the essentials: listen, root, index, and server_name. Remove commented examples to keep the file focused. Example minimal helloworld server block:
Notes:
  • Do not use listen 80 default_server; in more than one server block — this causes a duplicate default server error.
  • Set server_name to the hostname you intend to serve (we’ll test this with a Host header).
Set server_name to the hostname you intend to serve (for example, helloworld.com). NGINX uses the Host header to select the matching server block; if no match is found, NGINX serves the first matching server block (often the default).

4. Create the document root and index page

Create the document root that matches the root directive and add a basic index.html:
Create the index file:
Ensure the file is named index.html because the server block uses index index.html in its index list.

5. Enable the site (sites-available → sites-enabled)

Enable the site by creating a symbolic link from sites-available to sites-enabled:
Verify the symlink exists:

6. Test NGINX configuration and reload

Always test NGINX configuration syntax before reloading:
Common error example:
This indicates two server blocks are configured as the default_server. Fix the conflicting listen lines (remove default_server from one) or disable the default site, then re-run the test:
Reload NGINX to apply the new configuration:
(Alternatively: systemctl reload nginx.)

7. Test locally using the Host header

If you switched to root, return to your regular user for testing:
A plain curl localhost will still return the default “Welcome to nginx!” page because the request lacks a Host header matching helloworld.com:
To test the helloworld.com site without DNS, send the Host header explicitly:
You should get the Hello World page:
If you pass a Host header that doesn’t match any server_name in your enabled configs (for example Host: someunknown), NGINX will serve the first available server block (often the default). Proper server_name configuration and testing are important.

Quick reference: useful paths and commands

Troubleshooting tips

  • Duplicate default server error: remove default_server from one listen directive or disable the default site.
  • 403 Forbidden: check filesystem permissions and ownership for /var/www/helloworld and the index file.
  • Still seeing default page: ensure your Host header matches server_name or update /etc/hosts/DNS accordingly.

8. Next steps

  • If you want this site reachable from other machines, open port 80 in your firewall. On Ubuntu, use ufw:
  • Use DNS or update /etc/hosts for a friendly hostname (e.g., helloworld.com) in your testing environment.
  • For production, configure TLS (HTTPS) using a certificate from Let’s Encrypt or another CA, and consider a reverse proxy or load balancer if needed.
Resources and further reading: That’s it — you now have a minimal NGINX-hosted site and know how to test virtual hosts locally using the Host header.

Watch Video