How to Install Nginx on Ubuntu 24.04

Introduction

Nginx is a high-performance, open-source web server and reverse proxy known for its scalability and efficiency. Nginx is popular for serving static content, load balancing, and managing high-traffic websites. Nginx supports modern web protocols and offers robust security features, making it a favorite among developers. The server's lightweight footprint, ease of configuration, and ability to handle multiple connections simultaneously contribute to its popularity.

In this guide, you will install Nginx on Ubuntu 24.04.

Prerequisites

Before you begin, ensure you have the following:

Install Nginx

You can install Nginx from the Ubuntu repositories. Follow the steps below to install Nginx using the apt command.

  1. SSH to your Ubuntu server.
  2. Update your system's package information index.

    CONSOLE
    $ sudo apt update
    
  3. Install Nginx.

    CONSOLE
    $ sudo apt-get install nginx
    

Allow Nginx Ports Through the Firewall

By default, Nginx uses port 80 for HTTP traffic and port 443 for HTTPS traffic. To open the ports, use the Uncomplicated Firewal (UFW).

  1. Allow HTTP port 80 through the firewall.

    CONSOLE
    $ sudo ufw allow 80
    
  2. Allow HTTPS port 443 through the firewall.

    CONSOLE
    $ sudo ufw allow 443
    
  3. Enter your server's public IP address on a web browser.

    http://192.0.0.1
    
  4. Ensure Nginx displays the default web page.

Understand Nginx Configurations

Several files control how the Nginx webserver works as detailed below.

  • /etc/nginx/nginx.conf: Main configuration file containing directives that define how Nginx should behave, including settings for server blocks, virtual hosts, proxy settings, and more.
  • /etc/nginx/sites-available/: Contains server block directories for different domains or IP addresses.
  • /etc/nginx/sites-enabled/: Contains symbolic links to the active configurations.

Conclusion

You installed Nginx on Ubuntu 24.04 using the apt command and opened the default Nginx port through the firewall. You've successfully loaded the default web page to verify the installation and understood the default settings directories. You can now use Nginx to power your website.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js