- 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
Hostheader withcurl
1. Verify NGINX is installed and running
Check the service status and start NGINX if it is not running:2. Become root (optional)
You can continue usingsudo for each command, or switch to root temporarily:
3. Inspect the NGINX configuration directory
List the NGINX config files and thesites-available directory:
4. Create a new virtual host configuration
Copy the default site configuration to create a new site calledhelloworld:
/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:
server_namemust match theHostheader that clients send (we usehelloworld.comin this example).rootis 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 simpleindex.html:
6. Enable the site
Enable the site by creating a symbolic link fromsites-available to sites-enabled:
7. Test NGINX configuration for syntax errors
Run the NGINX config test:default_server in more than one server block, you might see an error like:
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
Becausehelloworld.com is not necessarily configured in your DNS, test by sending a Host header:
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 localhostreturns the default welcome page after enabling your site, ensure yourHostheader matches theserver_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.
Links and references
- NGINX official docs: https://nginx.org/en/docs/
- Systemd service management: https://www.freedesktop.org/wiki/Software/systemd/
- curl manual: https://curl.se/docs/manpage.html
/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.