In this tutorial, you’ll learn how to deploy a simple Hello World site using Nginx. By the end, you’ll have a custom virtual host serving your own HTML page.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
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: