How to Install Nginx Web Server on Ubuntu 26.04

Updated on 24 April, 2026
Install and configure the Nginx high-performance web server on an Ubuntu 26.04 for content delivery, reverse proxying, and load balancing.
How to Install Nginx Web Server on Ubuntu 26.04 header image

Nginx is a high-performance, open-source web server that serves static and dynamic content, and also functions as a reverse proxy, load balancer, and HTTP cache. Its event-driven architecture handles thousands of concurrent connections efficiently, making it a popular choice for production deployments and application delivery.

This article explains how to install Nginx on an Ubuntu 26.04 server, configure a virtual host to serve a sample web application, secure the server with a trusted SSL certificate from Let's Encrypt, and set up firewall rules for HTTP and HTTPS traffic.

Prerequisites

Before you begin, you need to:

Install Nginx on Ubuntu 26.04

The default Ubuntu 26.04 APT repositories include the Nginx package. The following steps update the package index and install the web server.

  1. Update the APT package index.

    console
    $ sudo apt update
    
  2. Install Nginx.

    console
    $ sudo apt install nginx -y
    
  3. Confirm the installed Nginx version.

    console
    $ nginx -version
    

    Your output should be similar to the one below:

    nginx version: nginx/1.28.2 (Ubuntu)

Manage the Nginx System Service

Nginx runs as a systemd service on Ubuntu, providing standard controls for starting, stopping, and restarting the web server process. The following steps enable automatic startup on boot and demonstrate the core service management commands.

  1. Enable Nginx to start automatically at boot time.

    console
    $ sudo systemctl enable nginx
    
  2. Start the Nginx service.

    console
    $ sudo systemctl start nginx
    
  3. Stop the Nginx service.

    console
    $ sudo systemctl stop nginx
    
  4. Restart the Nginx service.

    console
    $ sudo systemctl restart nginx
    
  5. Verify that Nginx is active and running.

    console
    $ sudo systemctl status nginx
    

    Your output should be similar to the one below:

    ● nginx.service - A high performance web server and a reverse proxy server
         Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
         Active: active (running) since Wed 2026-03-25 18:48:49 UTC; 6s ago

    The Active: active (running) status confirms that Nginx is operational. If the status shows active (failed), stop any process occupying HTTP port 80 and restart the Nginx service.

Set Up Firewall Rules

Uncomplicated Firewall (UFW) is active by default on Ubuntu 26.04. Nginx requires open ports for HTTP and HTTPS traffic. The following steps configure the firewall to allow incoming connections on both ports.

  1. Allow HTTP traffic on port 80.

    console
    $ sudo ufw allow 80/tcp
    
  2. Allow HTTPS traffic on port 443.

    console
    $ sudo ufw allow 443/tcp
    
  3. Verify the active firewall rules.

    console
    $ sudo ufw status
    

    Your output should be similar to the one below:

    Status: active
    
    To                         Action      From
    --                         ------      ----
    80/tcp                     ALLOW       Anywhere
    443/tcp                    ALLOW       Anywhere
    22                         ALLOW       Anywhere
    80/tcp (v6)                ALLOW       Anywhere (v6)
    443/tcp (v6)               ALLOW       Anywhere (v6)
    22 (v6)                    ALLOW       Anywhere (v6)

Create a Web Root Directory

The web root directory stores the files that Nginx serves when a client requests the domain. The following steps create the directory structure and a sample HTML page.

  1. Create the web root directory for the virtual host.

    console
    $ sudo mkdir -p /var/www/app.example.com
    
  2. Create a sample index.html file in the web root directory.

    console
    $ sudo nano /var/www/app.example.com/index.html
    
  3. Add the following HTML content to the file.

    html
    <html>
        <head></head>
        <body>
            <h1>Hello World</h1>
        </body>
    </html>
    

    Save and close the file.

Create a New Nginx Virtual Host

Virtual host configurations direct Nginx to serve specific content based on the requested domain name and the corresponding document root directory. The following steps define a server block for the sample domain, enable it, and verify that Nginx serves the expected content.

  1. Create a new virtual host configuration file.

    console
    $ sudo nano /etc/nginx/sites-available/app.example.com.conf
    
  2. Add the following server block configuration.

    ini
    server {
        listen 80;
        listen [::]:80;
    
        server_name app.example.com;
    
        root /var/www/app.example.com;
        index index.html;
    
        location / {
            try_files $uri $uri/ =404;
        }
    }
    

    Save and close the file.

    This configuration instructs Nginx to listen on port 80 for requests matching the app.example.com domain and serve files from the /var/www/app.example.com directory.

  3. Enable the virtual host by creating a symbolic link in the sites-enabled directory.

    console
    $ sudo ln -s /etc/nginx/sites-available/app.example.com.conf /etc/nginx/sites-enabled/
    
  4. Test the Nginx configuration for syntax errors.

    console
    $ sudo nginx -t
    
  5. Restart Nginx to activate the new virtual host.

    console
    $ sudo systemctl restart nginx
    
  6. Verify the virtual host by sending a request to the domain using curl.

    console
    $ curl http://app.example.com
    

    A successful response returns the HTML content:

    <html>
        <head></head>
        <body>
            <h1>Hello World</h1>
        </body>
    </html>

Secure the Nginx Web Server

SSL certificates encrypt traffic between a client browser and the Nginx web server over HTTPS. By default, Nginx listens on the unencrypted HTTP port 80. The following steps install Certbot and generate a trusted Let's Encrypt SSL certificate to enable HTTPS on your virtual host.

  1. Install the Certbot Let's Encrypt client and the Nginx plugin.

    console
    $ sudo apt install certbot python3-certbot-nginx -y
    
  2. Verify the installed Certbot version.

    console
    $ certbot --version
    

    Your output should be similar to the one below:

    certbot 5.4.0
  3. Generate an SSL certificate for your domain. Replace app.example.com with your actual domain name.

    console
    $ sudo certbot --nginx -d app.example.com --agree-tos
    

    Follow the on-screen prompts to complete the certificate generation. Certbot automatically configures the Nginx virtual host to use the new SSL certificate.

  4. Verify that HTTPS is active by sending a request to your domain. Replace app.example.com with your actual domain name.

    console
    $ curl https://app.example.com
    

    A successful response returns the HTML content served over HTTPS:

    <html>
        <head></head>
        <body>
            <h1>Hello World</h1>
        </body>
    </html>

Conclusion

You have installed and configured Nginx on an Ubuntu 26.04 server with a virtual host, secured it with a Let's Encrypt SSL certificate, and configured firewall rules for HTTP and HTTPS traffic. Nginx supports multiple virtual hosts and integrates with backend services such as PHP-FPM and database servers for dynamic application delivery. For more configuration options, refer to the official Nginx documentation.

Comments