UbuntuUbuntu Based

How To Install Nginx on Ubuntu 24.04 LTS

Install Nginx on Ubuntu 24.04

In this tutorial, we will show you how to install Nginx on Ubuntu 24.04 LTS. Nginx (pronounced “engine-x”) is a powerful, high-performance web server that has gained immense popularity due to its lightweight nature, stability, and rich feature set. It is known for its ability to efficiently handle a large number of concurrent connections while consuming minimal system resources. In the modern server landscape, Ubuntu 24.04 has emerged as a reliable and widely used Linux distribution for hosting web applications.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Nginx web server on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install Nginx on Ubuntu 24.04 Noble Numbat

Step 1. Updating the Package Repository.

To prepare your Ubuntu 24.04 server for Nginx installation, start by updating the system packages to their latest versions. Open a terminal and run the following commands:

sudo apt update

This command will fetch the latest package information from the Ubuntu repositories, allowing you to install the most recent version of Nginx and its dependencies. Updating the package repository is crucial to maintaining the security and stability of your system.

Step 2. Installing Nginx on Ubuntu 24.04.

  • Installing Nginx from the Ubuntu Repository

Ubuntu’s package repository provides a straightforward method to install Nginx. This method ensures compatibility and easy installation through managed packages. Install Nginx by executing:

sudo apt install nginx

This command installs Nginx and any required dependencies. Once installed, the Nginx service will start automatically. To verify that Nginx is running, use:

sudo systemctl status nginx

If the installation was successful, you should see an output indicating that the Nginx service is active and running.

  • Installing Nginx from the Official Nginx Repository

For those requiring the latest features and updates, installing Nginx from its official repository is recommended. First, add the repository to your system:

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

Next, import the repository’s key:

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor -o /usr/share/keyrings/nginx-archive-keyring.gpg

Update your package list and install Nginx:

sudo apt update
sudo apt install nginx

This command will download and install the latest stable version of Nginx from the official repository.

Step 4. Configuring the Firewall,

To enhance the security of your Nginx web server, it’s crucial to configure the firewall to allow only necessary traffic. Ubuntu 24.04 comes with a firewall configuration tool called UFW (Uncomplicated Firewall) that simplifies the process of managing firewall rules. Enable traffic on Nginx profiles by running:

sudo ufw allow 'Nginx Full'

This command configures the firewall to allow both HTTP (port 80) and HTTPS (port 443) traffic.

Verify the firewall rules by running:

sudo ufw status

Step 3. Basic Nginx Configuration

After installation, the basic configuration of Nginx is necessary to serve web content. Nginx configurations are stored in /etc/nginx/nginx.conf. Start by reviewing this file and adjusting the basic settings like worker processes and connection limits to optimize performance.

Set up a server block (similar to virtual hosts in Apache) by creating a new configuration file under /etc/nginx/conf.d/:

sudo nano /etc/nginx/conf.d/example.com.conf

Include the following configuration to serve a static website:

server {
    listen 80;
    server_name example.com www.example.com;

    location / {
        root /var/www/html;
        index index.html index.htm;
    }
}

Test the Nginx configuration for any syntax errors by running:

sudo nginx -t

If no errors are reported, proceed to reload the Nginx service to apply the changes:

sudo systemctl reload nginx

Step 4. Testing the Nginx Installation.

To ensure that Nginx is correctly installed and configured, access your server’s IP address or domain name from a web browser. You should see the default Nginx welcome page or your own content if you’ve configured a server block.

Install Nginx on Ubuntu 24.04 Noble Numbat

Step 4. Securing Nginx with SSL/TLS.

Securing your Nginx server with SSL/TLS is crucial for protecting data. Use Let’s Encrypt to obtain a free SSL certificate:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Follow the prompts to configure SSL, and Certbot will automatically adjust your Nginx configuration to use HTTPS.

Test the SSL configuration by accessing your website using HTTPS in a web browser:

https://example.com

If the SSL certificate is properly installed, you should see a secure padlock icon in the browser’s address bar.

Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing the Nginx high-performance web server on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the Nginx website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button