Skip to main content
This guide walks through creating a minimal “Hello World” site and serving it with NGINX on a Linux host. You’ll:
  • Verify NGINX is installed and running
  • Create a new site configuration in /etc/nginx/sites-available
  • Create site content under /var/www/helloworld
  • Enable the site with a symlink in /etc/nginx/sites-enabled
  • Test the site locally by sending a Host header with curl
Important commands and file snippets are provided in the sequence you should run them.

1. Verify NGINX is installed and running

Check the service status and start NGINX if it is not running:
Confirm NGINX responds on localhost:
You should see the default NGINX welcome page, for example:

2. Become root (optional)

You can continue using sudo for each command, or switch to root temporarily:

3. Inspect the NGINX configuration directory

List the NGINX config files and the sites-available directory:

4. Create a new virtual host configuration

Copy the default site configuration to create a new site called helloworld:
Edit /etc/nginx/sites-available/helloworld and simplify its server block. Remove comments and any IPv6 listen line if present. Ensure the server block looks like this:
Notes:
  • server_name must match the Host header that clients send (we use helloworld.com in this example).
  • root is where NGINX will look for the site files.
Avoid having two server blocks configured with listen 80 default_server simultaneously. That causes a duplicate default server error. Keep only one default_server or remove the directive from additional site configs.

5. Create the site directory and index page

Create the site folder and a simple index.html:

6. Enable the site

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

7. Test NGINX configuration for syntax errors

Run the NGINX config test:
If you left default_server in more than one server block, you might see an error like:
Remove default_server from extra server blocks and re-run nginx -t. A successful test shows:

8. Reload NGINX to apply the new configuration

Reload the running service to apply changes:

9. Exit root (if applicable)

If you switched to root earlier, return to your normal user:

10. Test the site locally with curl

Because helloworld.com is not necessarily configured in your DNS, test by sending a Host header:
If you pass a Host header that doesn’t match any server_name, NGINX will serve the first enabled configuration (typically the default site):
When multiple server blocks exist, NGINX tries to select the best match for the Host header. If none match, it serves the first enabled configuration (often the default). To avoid accidentally serving the wrong site, remove the default config, or ensure each server_name is explicit and unique.

Quick reference: key files and commands

Troubleshooting tips

  • If curl localhost returns the default welcome page after enabling your site, ensure your Host header matches the server_name, e.g. curl --header "Host: helloworld.com" localhost.
  • Permissions: NGINX needs read access to files in /var/www/helloworld. Adjust ownership or permissions if files are inaccessible.
  • Ports/firewall: To expose the site externally, open port 80 in your host firewall or cloud security group.
That’s it — you now have a minimal NGINX virtual host serving a Hello World page from /var/www/helloworld. To make the site available to external users, ensure your DNS points helloworld.com to the server and that port 80 is allowed through any firewalls.

Watch Video