Cyber Month Offers - Up to 41% OFF

How to Install Nginx on Ubuntu 26.04: Step-by-Step

How to Install Nginx on Ubuntu 26.04: Step-by-Step
Published on Oct 28, 2026 Updated on Oct 29, 2026

Nginx is one of the most popular web servers in use today, renowned for its speed, stability, and ability to handle high traffic loads with minimal resource usage. It is free and open-source and powers a huge share of the web, from small personal blogs to some of the busiest sites on the internet.

It’s a great choice for developers and operations teams because it serves web content exceptionally fast. Beyond serving web content, Nginx can be configured as a reverse proxy to route traffic to backend services or act as a load balancer, sitting in front of application servers to distribute traffic, terminate SSL/TLS, and handle failovers. Its ability to handle high-concurrency traffic with low resource usage makes it a preferred choice for small businesses and large organizations.

In this guide, we'll walk through installing and configuring Nginx on Ubuntu 26.04, from initial setup to verifying your web server is up and running and securing it with an SSL/TLS certificate.

Scalable VPS Hosting

Deploy fast, secure VPS for websites, apps, and dev environments. Scale on demand, manage with full root access, and get 24/7 expert support.

#Why Use Nginx?

There are many reasons why people choose to use Nginx for their applications and databases, but among the most important are its handling of dense traffic volumes while being easy to use as well as set up. Let’s take a closer look.

#1. Great Performance Under High Concurrency

Some web servers use the traditional approach of serving requests where one process or thread handles each connection. While this model may be simple and easy to implement for modest traffic, handling thousands of concurrent connections introduces performance bottlenecks and resource overhead. This is where Nginx comes in.

Nginx uses an event-driven asynchronous architecture. Instead of assigning a dedicated worker to every connection, it uses a relatively small number of worker processes to manage multiple connections, achieving high concurrency, ideal for high-traffic websites, reverse proxies, and APIs serving multiple clients.

#2. Reverse Proxy and Load Balancing Capabilities

Nginx is much more than just a web server. You can configure it to work as a reverse proxy or load balancer, which is invaluable for DevOps engineers and sysadmins.

As a reverse proxy, you can configure it to accept requests and forward them to backend services. In a load-balancer setup, Nginx is configured to distribute requests across multiple backend servers to achieve high availability. It supports multiple load balancing methods, including round-robin, least connections, least time, and IP hashing.

#3. Lightweight and Easy to Install

Nginx runs reliably on relatively modest Linux servers, making it a good web server option for personal projects, small businesses, and enterprise environments. Its low operational overhead means more CPU and memory will be available for other resource-demanding workloads.

Nginx is packaged in the official repositories of Ubuntu, Debian, and RHEL-based distributions such as Rocky and AlmaLinux (as the nginx package). A basic install is usually a single command:

  • Debian/Ubuntu: sudo apt install nginx
  • RHEL/Rocky/AlmaLinux: sudo dnf install nginx
  • Arch: sudo pacman -S nginx

Once installed, you can start it by running: sudo systemctl enable --now nginx

#4. Efficient Delivery of Static Content

Nginx excels at serving static files with negligible resource overhead. These files include:

  • HTML documents
  • CSS Stylesheets
  • JS files
  • Images, GIFs, and downloadable files

It can serve these files directly rather than passing every request to an application backend such as Node.js or Python.

#5. TLS/SSL Termination and Other Security Features

Nginx supports TLS/SSL termination, implying it can handle HTTPS connections and forward requests to backend applications. This helps you secure your registered domain with a TLS/SSL certificate.

In addition, it can let you:

  • Add security-related HTTP headers
  • Redirect HTTP traffic to HTTPS
  • Set request-size limits
  • Apply rate limits to reduce abusive request traffic.
  • Apply IP-based restrictions using allow and deny directives. This allows you to restrict traffic to specific IP addresses or subnets
  • Implement basic authentication by using username and password prompts' via auth_basicand.htpasswd` files.

#Prerequisites

To install Nginx, here is what you need before getting started:

A fully qualified domain name (FQDN) pointing to the server’s public IP address. This is optional and is only a requirement for users intending to host their own website and secure it with an SSL/TLS certificate.

#Instructions to Install Nginx on Ubuntu 26.04

Now that you know what Nginx is and why most organizations prefer it, let’s focus on the installation. First, we’ll install Nginx from the default Ubuntu repositories. Then, we’ll create a server block file to host your personal website and enable TLS/SSL for your domain to secure the connection.

#Step 1: Update Your System

To get things rolling, log in to your server and update the local package index. This is essential, especially when starting with a fresh VPS.

Command Line
sudo apt update

Once updated, proceed to the next step.

#Step 2: Install Nginx

The most straightforward way to install Nginx is from Ubuntu’s default APT repositories. This ships with all the configuration files needed to get everything up and running, including setting up server blocks.

To install Nginx using this method, simply run:

Command Line
sudo apt install nginx 

Type Y when prompted and hit ENTER to proceed with the installation.

OutputInstalling:                     
  nginx
Installing dependencies:
  nginx-common
Suggested packages:
  fcgiwrap  nginx-doc  ssl-cert
Summary:
  Upgrading: 0, Installing: 2, Removing: 0, Not Upgrading: 0
  Download size: 655 kB
  Space needed: 1864 kB / 80.0 GB available
Continue? [Y/n] 

The command installs the Nginx web server package alongside other required dependencies.

#Step 3: Verify installation of Nginx

After installing a software package, it's good practice to verify that the installation succeeded. There are several ways to check whether Nginx is installed on your system.

Check the version by running the following command.

Command Line
nginx  -v

You should get the version displayed as shown; however, the version number is subject to change depending on when you are reading this tutorial.

Outputnginx version: nginx/1.31.6

You can also run the dpkg command to obtain the installed version.

Command Line
dpkg -l  | grep nginx

You should get something like this:

Outputii  nginx           1.31.6-1~noble                      amd64        high performance web server

Another way to check if Nginx is present on your system is to check the path to its executable. To do this, run the which command.

Command Line
which nginx

This is what will be displayed.

Output/usr/sbin/nginx

#Step 4: Managing the Nginx Systemd Service

By default, the Nginx service runs upon installation.

Confirm that the Nginx service runs as expected by using:

Command Line
sudo systemctl status nginx

This should give you the following output:

Output● 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 Fri 2026-09-25 19:43:44 EEST; 1min 25s ago
 Invocation: 6b69d49dd4a447d6b907720bc9b1487d
       Docs: man:nginx(8)
    Process: 1954 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 1955 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 1987 (nginx)
      Tasks: 5 (limit: 3502)
     Memory: 4.4M (peak: 11.4M)
        CPU: 67ms
     CGroup: /system.slice/nginx.service
             ├─1987 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ├─1990 "nginx: worker process"
             ├─1991 "nginx: worker process"
             ├─1992 "nginx: worker process"
             └─1993 "nginx: worker process"

After establishing that Nginx is running, you can run the ss command to check the TCP ports it's listening on with:

Command Line
sudo  ss  -pnltu  | grep  -i  nginx

You should see the following output, confirming Nginx is listening on TCP port 80 on your server on all interfaces.

Outputtcp   LISTEN 0      511          0.0.0.0:80        0.0.0.0:*    users:(("nginx",pid=20518,fd=6),("nginx",pid=20517,fd=6),("nginx",pid=20516,fd=6),("nginx",pid=20515,fd=6),("nginx",pid=20513,fd=6))

You can enable Nginx to start every time you restart or boot into the system. To achieve this, execute the command:

Command Line
sudo systemctl enable nginx

To confirm the service is enabled, run:

Command Line
sudo systemctl is-enabled nginx

You should get enabled as the response. To disable the service, just execute the command:

Command Line
sudo systemctl disable nginx

If you check the service status, this time around, you will get disabled as the response.

To stop the Nginx service, run the command:

Command Line
sudo systemctl stop nginx

To start the service again, run:

Command Line
sudo systemctl start nginx

To restart Nginx, for example, in cases when you have made a change to its configuration files, run:

Command Line
sudo systemctl restart nginx

Alternatively, you can simply reload the service to effect the changes without restarting it. This helps prevent service interruption.

Command Line
sudo systemctl reload nginx

#Step 4: Configuring UFW Firewall

Uncomplicated Firewall (UFW) is the built-in firewall solution for Debian and Ubuntu-based Linux distributions. Like most enterprise and consumer firewalls, UFW denies all incoming traffic by default while allowing all outgoing. Inbound traffic is blocked to protect devices from hackers, external malware, and unsolicited external connection attempts.

Since this is a fresh VPS, you need to allow web traffic on ports 80 and 443 for HTTP and HTTPS traffic.

To allow web traffic in one command, run:

Command Line
sudo ufw allow 'Nginx Full'

This allows for both HTTP and HTTPS connections. Next, allow SSH connections so that you don't lock yourself out of the server.

Command Line
sudo ufw allow OpenSSH

Or by TCP port number.

Command Line
sudo ufw allow 22/tcp

To verify the allowed application profiles, run the command:

Command Line
sudo ufw app list
Output  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  Nginx QUIC
  OpenSSH

Next, enable the firewall for the rules to take effect.

Command Line
sudo ufw enable

When prompted about SSH disruption, confirm with y.

#Step 5: Access Nginx from a Web Browser

With the firewall configured and only the required services allowed, open your browser and visit your server’s IP or registered domain name. You should see the default Nginx web page, confirming that Nginx is up and running.

nginx-default-webpage

On the command line, you can send an HTTP GET request using the curl command as shown.

Command Line
curl -I localhost

You should get the response headers, confirming Nginx is running as expected and serving the default page.

OutputHTTP/1.1 200 OK
Server: nginx/1.31.6
Date: Thu, 24 Sep 2026 17:31:28 GMT
Content-Type: text/html
Content-Length: 896
Last-Modified: Tue, 15 Sep 2026 12:54:15 GMT
Connection: keep-alive
ETag: "6aa93ff7-380"
Accept-Ranges: bytes

#Step 6: Create a server block for your domain (optional)

At this point, Nginx is installed and running correctly. However, you'll need to continue past Step 5 if you intend to host your own website; otherwise, your browser will keep displaying the default Nginx welcome page.

To host your website, you need to create a server block file, which is the equivalent of a virtual host file in Apache. A server block lets you host your website and also host multiple sites on the same server, each with its own configuration files and settings.

To create a server block file, first create the website directory. Replace example.com with your domain name.

Command Line
sudo mkdir -p /var/www/example.com/html

Next, assign ownership of the directory to the currently logged-in user and group.

Command Line
sudo chown -R  $USER:$USER /var/www/example.com/html

Set permissions as shown to allow read and execute permissions to the group and other users (public).

Command Line
sudo chmod -R 755 /var/www/example.com

Once the directory has been created and the correct ownership and permissions are configured, create a sample index.html file with:

Command Line
sudo nano /var/www/example.com/html/index.html

In the real world, this would be your real website file placed in the html directory alongside other files.

Paste the following lines for the test webpage:

Command Line
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sample Site</title>
</head>
<body style="font-family: Arial, sans-serif; max-width: 700px; margin: 40px auto; padding: 0 20px; line-height: 1.6; color: #222;">
    <header style="border-bottom: 1px solid #ddd; padding-bottom: 16px; margin-bottom: 24px;">
        <h1 style="margin: 0; font-size: 28px;">Welcome to example.com!</h1>
        <p style="margin: 8px 0 0; color: #555;">A simple example site.</p>
    </header>
</body>
</html>

By convention, Ubuntu keeps Nginx's server block configuration files in the /etc/nginx/sites-available/ directory. This is where we are going to create the server block file.

Create the server block file using:

Command Line
sudo nano /etc/nginx/sites-available/example.com
  1. Add the following lines of code:
Command Line
server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;

    root /var/www/example.com/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Next, enable the server block by running the following command:

Command Line
sudo ln -s /etc/nginx/sites-available/example.com   /etc/nginx/sites-enabled/

This creates a symbolic link in the /etc/nginx/sites-enabled/ directory. You can confirm the link was created by running:

Command Line
ls -l /etc/nginx/sites-enabled/

The output should display two symbolic links: the existing default link and the newly created one for your domain.

Outputlrwxrwxrwx 1 root root 34 Sep 25 19:30 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 45 Sep 25 20:04 example.com -> /etc/nginx/sites-available/example.com

Once the server block is enabled, you’ll need to disable or unlink the default one since it's still active. This is because the default server block will still take precedence, and the Nginx web page will continue to be displayed every time you visit your domain in a web browser if this step is not taken.

To unlink the default link, run the command:

Command Line
sudo unlink /etc/nginx/sites-enabled/default

Next, run the following command to check if all the configurations are sound.

Command Line
sudo nginx -t

A successful result should look like what we have here:

Outputnginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart Nginx to apply the changes made.

Command Line
sudo systemctl restart nginx

Now you can access your server using your registered domain. You should be able to view the sample webpage.

nginx-default-webpage-http-not-secure

#Step 7: Configure Let's Encrypt TLS Certificate (Recommended)

Up to this point, the server block is serving your website files as expected, but one issue remains. Your website is using the HTTP protocol, which sends everything in cleartext, from passwords and session cookies to form data and credit card details. Anyone on a public WiFi network can intercept traffic with basic packet-sniffing tools and steal sensitive credentials.

To secure your site, it’s highly recommended to switch to the HTTPS protocol. Modern web standards push HTTPS over plain HTTP for security, trust, and better SEO ranking.

To enable your website to use HTTPS, you need to install an SSL/TLS certificate, which will encrypt web traffic flowing to and from the server.

There are numerous ways to configure an SSL/TLS certificate on your server. A free and convenient approach is to leverage Let’s Encrypt. This is a fully automated, no-cost certificate authority (CA) that offers free SSL/TLS certificates. The certificate is valid for only 90 days, after which you need to renew it.

To enable Let’s Encrypt TLS/SSL, first install certbot by running:

Command Line
sudo snap install --classic certbot

Certbot is a client for obtaining and managing TLS/SSL certificates from Let's Encrypt.

Next, create a symbolic link to the /usr/local/bin/ directory with:

Command Line
sudo ln -s /snap/bin/certbot  /usr/local/bin/certbot

Once installed, confirm the version by running:

Command Line
certbot --version

Next, be sure to reload Nginx.

Command Line
sudo systemctl reload nginx

Run the following certbot command to request and enable the SSL/TLS certificate on your website.

Command Line
sudo certbot --nginx

You will be prompted for the following details: Your email address Agreement to the Let’s Encrypt terms Whether you’d like to redirect HTTP to HTTPS for your domain

The certbot plugin will proceed to obtain the certificate and automatically modify the Nginx configuration to enable HTTPS. You will see a lot of verbose output as this happens.

Once the command successfully executes, confirm deployment of the SSL certificate by running:

Command Line
sudo certbot certificates

You should see the following output, confirming that the SSL certificate has been enabled:

Output- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: example.com
    Serial Number: 59f1469cebc7d0dca87de55093c9b08828e
    Key Type: ECDSA
    Identifiers: example.com  www.example.com
    Expiry Date: 2026-12-24 16:15:11+00:00 (VALID: 88 days)
    Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

You can also check Nginx’s configuration as follows:

Command Line
sudo nginx -T 2>/dev/null | grep -E "listen 443|ssl_certificate"

You should get the following output:

Outputlisten 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot

Finally, reload your browser. This time around, you’ll notice the URL switches to https://example.com.

nginx-server-secured-with-https-ssl-certificate

To view detailed certificate details, click the Settings icon on the URL, then navigate to Connection is Secure > Certificate is valid.

nginx-server-lets-encrypt-ssl-certificate-information

#Nginx Troubleshooting Tips

Sometimes, you might experience technical issues running your web server. This can range from the web server not running to not being able to access your site. Here are some of the common Nginx issues and how to resolve them.

#1) Nginx Not Starting

If your web server has failed to start, consider performing the following checks:

Narrow down to the actual error

If the Nginx systemd service fails to start, consider checking its status:

Command Line
sudo systemctl status nginx

If it’s not running, consider running the journactl command to query system logs.

Command Line
sudo journalctl -xeu nginx --no-pager | tail -50

You can also follow the error logs in real-time to view the error messages.

Command Line
sudo tail -50 /var/log/nginx/error.log

The above commands usually pinpoint the exact problem (a line number in a config file or a bind error).

Check the configuration syntax

Another useful tip is to check syntax errors in the main configuration file. To do this, run the command:

Command Line
sudo nginx -t

The command catches syntax errors and indicates the file affected and the line that’s causing the error. Common causes include duplicate server_name or listen directives, typos in directive names, and missing semicolons at the end of a directive.

Once you spot an error and rectify it, be sure to reload or restart Nginx for the changes to come into effect.

Command Line
sudo systemctl reload nginx 

OR

Command Line
sudo systemctl restart nginx 

Then verify its status again to ensure it is running as expected.

Command Line
sudo systemctl status nginx 

Check for port 80 conflicts

There is a good chance that another web server (such as Apache) is already running on port 80, effectively blocking Nginx from using the port.

To view applications running on that port, run the ss command as follows:

Command Line
sudo ss -tulpn | grep ':80 '

If another process (such as Apache) holds the port, stop it as shown.

Command Line
sudo systemctl stop apache2

Then start the Nginx service.

Command Line
sudo systemctl start nginx

If there are no configuration errors and no other application is using port 80, Nginx should be able to start.

#2) The 403 Forbidden Error

The 403 Forbidden error in your browser means Nginx received the request but refused to serve it. To resolve it, run the following checks:

Check that the index.html file exists

The 403 forbidden error is usually a result of a missing index.html file in the web root directory. To resolve this, ensure the index.html file is present in the /var/www/example.com/html path.

Wrong directory ownership or incorrect root path

There’s a good chance files in the /var/www/example.com/ directory were copied with root or restrictive permissions.

Additionally, there’s a possibility the /var/www/example.com/ directory isn’t readable by the Nginx user.

To fix these issues, ensure the correct directory ownership is properly assigned:

Command Line
sudo chown -R  $USER:$USER /var/www/example.com/html

Also, set the directory permissions to allow read and execute permissions to the group and other users (public).

Command Line
sudo chmod -R 755 /var/www/example.com

#3) Certbot Failing to Install Let’s Encrypt TLS/SSL Certificate

To troubleshoot Certbot certificate failures, follow the steps outlined:

Check Certbot error details

Run the following command to check the actual error and why the certificate failed.

Command Line
sudo certbot certificates 
sudo tail -100 /var/log/letsencrypt/letsencrypt.log

Verify DNS resolution

DNS issues are the most common causes of certbot certificate failures. Ensure your domain’s A record points to your server’s public IP. You can achieve this using the dig command as shown:

Command Line
dig +short example.com A 
dig +short www.example.com A

The output should reveal your server’s public IP address. Once this is confirmed, wait for propagation to complete before retrying.

Ensure port 80 is open

A blocked port 80 on the firewall usually results in errors such as Connection refused, Timeout during connect (likely firewall problem).

To resolve this problem, check if port 80 is open on the UFW firewall:

Command Line
sudo ufw status

If port 80 is missing from the output, open it alongside port 443 (for secure HTTPS) as shown.

Command Line
sudo ufw allow 80,443/tcp

Then reload the firewall to effect the changes.

Command Line
sudo ufw reload

#Conclusion

And that's it! You've successfully installed Nginx on Ubuntu 26.04. Beyond the basic installation, you also configured a server block to host a separate website and secured its traffic with a Let's Encrypt SSL/TLS certificate.

From here, consider implementing server hardening techniques to secure your system further. For more information about Nginx, check out the official Nginx documentation.

Cloud VPS Hosting

Starting at just €3.00 / month, get virtual servers with top-tier performance.

Share this article

Related Articles

Published on Sep 8, 2026 Updated on Sep 10, 2026

How to Install Prometheus on Ubuntu 26.04

Learn how to install Prometheus on Ubuntu 26.04 LTS, configure Node Exporter, create alert rules, and set up Alertmanager for reliable server monitoring alerts

Read More
Published on Jun 30, 2026 Updated on Jul 1, 2026

How to Install Node.js on Ubuntu 24.04

Learn how to install Node.js on Ubuntu 24.04 using APT, NodeSource, or NVM. Compare each method and choose the best option for your development needs.

Read More
Published on Jun 4, 2026 Updated on Jun 5, 2026

Debian vs. Ubuntu Server: Which Is Better for Hosting?

Compare Debian vs Ubuntu Server for hosting. Learn key differences in performance, security, stability, cloud support, and deployment.

Read More
No results found for ""
Recent Searches
Navigate
Go
ESC
Exit