Whether you’re a seasoned developer or just starting your journey in the world of web servers, getting familiar with Nginx is a valuable skill. Nginx is a powerful, open-source web server that excels in serving static content, reverse proxying, load balancing, and more. In this tutorial, we’ll take you through the process of testing your Nginx installation—a crucial step to ensure everything is set up correctly for your web projects.
Before we dive into testing Nginx, let’s make sure you have everything you need:
- Operating System: This tutorial assumes you’re using a Unix-based operating system, such as Linux or macOS.
- Nginx Installed: Ensure that Nginx is installed on your system. You can install it using your package manager (e.g.,
- Basic Terminal Knowledge: Familiarity with the terminal or command line will be helpful.
Verifying Nginx Installation
Checking Nginx Service Status
The first step is to check whether Nginx is up and running. Open your terminal and execute the following command:
systemctl status nginx
This command will provide information about the current status of the Nginx service. Look for “active (running)” to ensure that Nginx is running successfully.
Accessing the Default Page
Once you’ve confirmed that Nginx is running, it’s time to access the default page. Open your web browser and enter your server’s IP address or domain name. If everything is set up correctly, you should see the default Nginx landing page. This confirms that Nginx is listening to incoming connections and serving content.
Creating a Custom ‘Hello World’ Page
Now that you’ve verified the basic installation, let’s take it a step further by creating a simple “Hello World” HTML page and serving it through Nginx.
Creating the HTML File
Navigate to the Nginx web root directory, usually located at
/var/www/html/. Use your favorite text editor to create an HTML file named
sudo nano /var/www/html/index.html
Inside the file, add the following HTML code:
<!DOCTYPE html> <html> <head> <title>Hello Nginx!</title> </head> <body> <h1>Hello, Nginx!</h1> <p>This is a test page served by Nginx.</p> </body> </html>
Save and exit the text editor.
Testing the Custom Page
To test your custom page, open your web browser and navigate to your server’s IP address or domain name again. This time, you should see your “Hello World” page served by Nginx.
Congratulations! You’ve successfully tested your Nginx installation and served a custom webpage. This ‘Hello World’ moment marks the beginning of your journey with Nginx, opening doors to more advanced configurations and optimizations for your web projects. With Nginx’s versatility, you’re well-equipped to handle a wide range of web server tasks.