How to Install NGINX on Ubuntu and Configure the Default Webpage

How to Install NGINX on Ubuntu and Configure the Default Webpage

If you're working on a web project and need to quickly set up a web server on Ubuntu, NGINX is a great option. In this short guide, we will walk through how to install NGINX on your Ubuntu system and modify the default webpage.

Step 1: Update Your System

Before installing any new packages, it's good practice to update your package list to ensure everything is up to date:

sudo apt update        

Step 2: Install NGINX

Once your system is updated, install NGINX using the following command:

sudo apt install nginx -y        

This will download and install NGINX on your machine. To check if it's running, use:

sudo systemctl status nginx        

If it’s active and running, you're good to go!

Step 3: Access the Default NGINX Page

By default, NGINX serves a welcome page. You can view this by entering your server’s IP address in a web browser. For local testing, you can use localhost or 127.0.0.1.

https://localhost        

Step 4: Modify the Default Webpage

To modify the default webpage, follow these steps:

1. Navigate to the default web page directory:

   cd /var/www/html/        

2. Open the default file, index.nginx-debian.html, in a text editor like nano:

   sudo nano index.nginx-debian.html        

3. Edit the HTML content as desired, save the changes, and exit the editor. For example, you can replace the content with a custom message like:

    
<html>

<head><title>Welcome to My Custom NGINX Server</title></head>

<body>

<h1>Hello, World! This is my custom NGINX page!</h1>

</body>

</html>        

Step 5: Restart NGINX to Apply Changes

After editing the file, restart the NGINX server to ensure the changes take effect:

sudo systemctl restart nginx        

Conclusion

In just a few simple steps, you've set up an NGINX server on Ubuntu and customized its default webpage. NGINX is powerful and flexible, making it a great choice for hosting websites, reverse proxying, or load balancing. Happy coding!

Feel free to share your experiences and tips in the comments. I’d love to hear how you're using NGINX in your projects!

要查看或添加评论,请登录

Shina Gupta的更多文章

社区洞察

其他会员也浏览了