1. Verify and Start Nginx
First, confirm that Nginx is installed and running on your server.If Nginx isn’t installed, follow the official installation guide before proceeding.
2. Create a New Site Configuration
-
Switch to the Nginx configuration directory and assume root privileges:
-
Copy the default server block to a new file named
helloworld: -
Open
sites-available/helloworldin your preferred editor and replace its contents with:Directive Purpose listen 80; Accept HTTP requests on port 80 server_name Match the Hostheader tohelloworld.comroot Define the document root for this virtual host index Specify default files to serve try_files Serve requested files or return a 404 if not found
Removing
default_server ensures no port conflicts. Always test your configuration before reloading Nginx.3. Create the Site Content
Create the document root and add a simple HTML page:4. Enable the Site and Reload Nginx
-
Create a symbolic link in
sites-enabled: -
Test the syntax and reload Nginx:
5. Test Your Hello World Site
-
To view the default site again:
-
To test your custom site without DNS:
Expected response:
-
If you send an unknown host header, Nginx will serve the first server block alphabetically (the default site):
You can add an entry to
/etc/hosts for helloworld.com to test in a browser without DNS: