Step-by-Step Guide to Install Nginx on Ubuntu 24.04
To install Nginx, ensure you have access to your system with sudo privileges and access to the terminal. With that, the steps below will guide you through everything you should do to install and configure your firewall to start using Nginx. Follow along!
Step 1: Update the Repository
in Ubuntu 24.04, Nginx is available in its default repository. As such, you won’t have to add its repository. Before installing this Nginx version, let’s ensure we get the latest version by updating the package index.
Step 2: Install Nginx via APT
After refreshing the Ubuntu repository, execute the install command below to fetch and install the Nginx package. Ensure you confirm the prompt.
Confirm that Nginx has been installed by running the below command to display the installed version.
We’ve installed Nginx 1.24.0.
Step 3: Enable and Start the Nginx Service
Before we can use Nginx, we must start the Nginx service. Instead of starting it every time you want to use it, setting Nginx to start at boot time is better. To do so, enable the Nginx service and restart Nginx using the commands below.
$ sudo systemctl restart nginx
Next, check the Nginx service to ensure that it’s active (running).
Step 4: Configure the Firewall
Although the firewall automatically detects Nginx and allows its connection, we must ensure it registers it. You can also specify a different rule to use with Nginx.
For this guide, we don’t want to give Nginx full access. Instead, let’s specify that we only want to connect via HTTP. To save this configuration, execute the following command.
You can also give it HTTPS access, or if you want to allow HTTP and HTTPS, create a Nginx Full rule.
With our rule added successfully, let’s view the firewall status to verify further that we have our rule added correctly. Check the firewall status using the command below.
Step 5: Verify Nginx Works
A quick way of confirming that your Nginx installation was a success is by opening the Nginx landing page. You can do this in two ways. The first option involves opening your web browser and accessing your web page. For instance, if using localhost, we would open the site: http://localhost
You will get an Nginx welcome page confirming that Nginx is all set and ready for use.
Alternatively, you can visit the same web page using curl and check the output. If the output shows the same welcome message, your installation was successful.
Conclusion
Nginx is an open-source web server that can be installed and used on Ubuntu 24.04. The Nginx package is available from the Ubuntu repository. To install it, use APT. Next, configure your firewall to allow traffic via Nginx. We’ve discussed each step, and with this guide as a reference, you can install Nginx on Ubuntu 24.04.