How to Install Nginx on Ubuntu 24


Nginx is a popular web server used to handle high volumes of traffic due to its performance and resource efficiency. In this tutorial, we’ll go over the steps to install Nginx on Ubuntu 24.

Step 1: Update the Package List

Before installing any new software, it’s a good practice to update your system’s package list to ensure you’re getting the latest versions.

Open a terminal and run:

sudo apt update

This command fetches the latest package information from Ubuntu’s repositories.

Step 2: Install Nginx

With the package list updated, you can now install Nginx. Use the following command:

sudo apt install nginx -y

The -y flag automatically confirms the installation prompt.

Step 3: Adjust Firewall Settings

If you have a firewall enabled, you’ll need to allow HTTP and HTTPS traffic so that Nginx can serve web pages.

To list the applications that UFW (Uncomplicated Firewall) knows how to manage, run:

sudo ufw app list

You should see Nginx Full, Nginx HTTP, and Nginx HTTPS. Use Nginx Full to allow both HTTP and HTTPS traffic:

sudo ufw allow 'Nginx Full'

To verify that the firewall rule is active, use:

sudo ufw status

Step 4: Start Nginx

After installation, Nginx should start automatically. To confirm, you can check its status:

sudo systemctl status nginx

If it’s active (running), you’re all set! If not, start it manually with:

sudo systemctl start nginx

You can also enable Nginx to start automatically at boot:

sudo systemctl enable nginx

Step 5: Verify Installation

To check if Nginx is running properly, open a web browser and go to your server’s IP address. You should see the Nginx default welcome page, which means the installation was successful.

You can find your server’s IP address by typing:

hostname -I

Then navigate to http://your_server_ip in your browser.

Step 6: Basic Nginx Commands

Here are some essential Nginx commands:

  • Start Nginx: sudo systemctl start nginx
  • Stop Nginx: sudo systemctl stop nginx
  • Restart Nginx: sudo systemctl restart nginx
  • Reload Nginx (for configuration changes): sudo systemctl reload nginx
  • Check Nginx status: sudo systemctl status nginx

Conclusion

You now have Nginx installed and running on your Ubuntu 24 server! From here, you can start configuring Nginx to serve your website or application.

Leave a Reply

Your email address will not be published. Required fields are marked *

*