- 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
Hostheader.
1. Verify NGINX is running
Check the service status and start it if necessary:2. Become root and inspect NGINX configuration directories
To avoid prefixingsudo for each command, switch to root for the remainder of the setup (optional but convenient):
sites-available/ and sites-enabled/ among the configuration files. Then change into sites-available:
default file here.
3. Create a new site configuration
Copy the default site config to a new file namedhelloworld:
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:
- Do not use
listen 80 default_server;in more than one server block — this causes a duplicate default server error. - Set
server_nameto 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 theroot directive and add a basic index.html:
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 fromsites-available to sites-enabled:
6. Test NGINX configuration and reload
Always test NGINX configuration syntax before reloading:default_server. Fix the conflicting listen lines (remove default_server from one) or disable the default site, then re-run the test:
systemctl reload nginx.)
7. Test locally using the Host header
If you switched to root, return to your regular user for testing:curl localhost will still return the default “Welcome to nginx!” page because the request lacks a Host header matching helloworld.com:
helloworld.com site without DNS, send the Host header explicitly:
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_serverfrom onelistendirective or disable the default site. - 403 Forbidden: check filesystem permissions and ownership for
/var/www/helloworldand the index file. - Still seeing default page: ensure your
Hostheader matchesserver_nameor 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/hostsfor 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.
- NGINX official docs: https://nginx.org/en/docs/
- Ubuntu
ufwguide: https://help.ubuntu.com/community/UFW - curl manual: https://curl.se/docs/manpage.html
Host header.