How to Install Nginx on Ubuntu 26.04

Install Nginx on Ubuntu 26.04 – DevAnswers.net

We may earn a referral fee at no additional cost to you when you shop through the links on this page.

Ubuntu 26.04 LTS (Resolute Raccoon), released April 2026, is the latest long-term support release with security updates guaranteed until April 2031 (extendable to 2036 with Ubuntu Pro). It ships with Nginx 1.28 and PHP 8.5, making it an ideal choice for modern web hosting….

The following steps cover installing the Nginx web server, configuring UFW firewall rules for web traffic, verifying the service, and setting up a server block for your domain.

Prerequisites 

Before you begin, ensure you have a server running Ubuntu 26.04 (Resolute Raccoon) with a non-root user that has sudo privileges, plus SSH or console access. If you are setting up a server for the first time, see our initial server setup guide for Ubuntu 26.04 (Resolute Raccoon).

Installing Nginx 

Update the local package index to ensure the package manager has the latest information about available software versions, then install the nginx package:

Terminal
sudo apt update && sudo apt install -y nginx

This installs Nginx 1.28 from the Ubuntu 26.04 (Resolute Raccoon) repositories. The server starts automatically after installation.

Adjusting the Firewall 

Before testing Nginx, configure a firewall to allow external access to web ports while restricting other traffic. This guide uses UFW (Uncomplicated Firewall), which works identically on Ubuntu and Debian.

If you prefer not to use a firewall (e.g., local development or behind a cloud provider’s firewall), you can skip this step entirely.

If UFW is not already installed:

Terminal
sudo apt install -y ufw
Remote server? If managing via SSH (e.g., a VPS on DigitalOcean, AWS, Linode), you must allow SSH before enabling the firewall. Skipping this will lock you out immediately.

Allow SSH connections first (if connecting remotely):

Terminal
sudo ufw allow OpenSSH

Allow Nginx through the firewall:

Terminal
sudo ufw allow 'Nginx Full'

Enable the firewall:

Terminal
sudo ufw enable

If you see “Command may disrupt existing ssh connections. Proceed with operation (y|n)?” Press y and Enter.

Verify the status:

Terminal
sudo ufw status

You should see Nginx listed as well as OpenSSH if you’re using it.

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)

Verifying the Installation 

Nginx starts automatically after installation. Confirm the service is active:

Terminal
sudo systemctl status nginx

You should see active (running) in the output.

On some terminals, you may need to press q to exit this screen.

Test locally or from a remote machine:

Don’t know your IP? Run hostname -I for your local IP, or curl -4 icanhazip.com for your public IP on a VPS.
Terminal
curl http://localhost
# or from remote:
curl http://your_server_ip

If you see HTML output in the response, the install was successful.

If you have access to a browser, you should see the default Nginx welcome page displaying ‘Welcome to nginx!’.

The default Nginx welcome page is located at /var/www/html/index.nginx-debian.html.

Managing the Nginx Service 

Essential systemd commands for managing Nginx:

ActionCommandNotes
Stopsudo systemctl stop nginxHalts the service completely
Startsudo systemctl start nginxStarts if stopped
Restartsudo systemctl restart nginxFull restart (brief downtime)
Reloadsudo systemctl reload nginxGraceful reload (preferred for config changes)
Enable on bootsudo systemctl enable nginxAuto-start after reboot
Test configsudo nginx -tValidate config before reload
Always run sudo nginx -t before reloading. A config syntax error will prevent Nginx from starting, potentially taking your site offline.

Important File Locations 

Key paths to know for managing Nginx on Ubuntu 26.04 (Resolute Raccoon):

  • Default Web Root: /var/www/html — Your web content goes here.
  • Main Configuration: /etc/nginx/nginx.conf — Global configuration file.
  • Server Blocks: /etc/nginx/sites-available/ — Per-site configurations.
  • Enabled Sites: /etc/nginx/sites-enabled/ — Symlinks to active configurations.
  • Access Log: /var/log/nginx/access.log — All requests to your server.
  • Error Log: /var/log/nginx/error.log — Errors and diagnostics.

Setting Up a Server Block 

To serve content for your domain instead of the default page, configure a server block (Nginx’s equivalent of Apache’s virtual host).

Ensure your domain’s DNS A record points to your server’s public IP (configured at your domain registrar). Propagation can take up to 48 hours. For local testing, edit your /etc/hosts file on your client machine.

Create a Directory for Your Site 

Terminal
sudo mkdir -p /var/www/example.com

Create a Sample Page 

Terminal
echo '<html><head><title>Success</title></head><body><h1>Success! The Server Block is working.</h1><p>You can now replace this file with your own content.</p><p>Return to <a href="https://devanswers.net/series/lemp-stack/">LEMP Stack Documentation</a></p></body></html>' | sudo tee /var/www/example.com/index.html

Set Permissions 

Assign ownership to the web server user and configure group permissions:

Terminal
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 775 /var/www/example.com
sudo chmod -R g+s /var/www/example.com

Add your user to the www-data group so you can modify files without sudo:

Terminal
sudo usermod -aG www-data $USER
Log out and back in for the group membership to take effect. Verify with id.

Create the Server Block Configuration 

Terminal
sudo nano /etc/nginx/sites-available/example.com

Paste the following configuration (replace example.com with your domain):

example.com
server {
    listen 80;
    listen [::]:80;

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

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

    access_log /var/log/nginx/example.com-access.log;
    error_log /var/log/nginx/example.com-error.log;
}

Save and exit (press CTRL + X, press Y, then press ENTER)

The try_files directive tells Nginx to look for the exact URI first, then a directory, and return a 404 if neither exists. This prevents directory listing and handles clean URLs.

Enable the Site and Reload Nginx 

Create a symlink to enable your server block, remove the default site symlink, and reload Nginx:

Terminal
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t && sudo systemctl reload nginx
Unlike Apache, Nginx does not have a2ensite or a2dissite commands. You manage sites by creating and removing symlinks in /etc/nginx/sites-enabled/ manually.

Test It 

Visit http://example.com in your browser. As long as your domain’s A record points to your server’s IP, you should see the sample page.

Browser at http://example.com showing the sample page: Success! The Server Block is working.

Conclusion 

You now have Nginx 1.28 running on Ubuntu 26.04 (Resolute Raccoon) with a configured server block.

Your server is ready for the next steps: installing a database server (MariaDB or MySQL), adding PHP-FPM for dynamic content, or deploying your application. For production sites, consider adding SSL/TLS encryption with Let’s Encrypt.

Next · step 2 of 4How to Install MySQL on Ubuntu 26.04
Support DevAnswers
Written, tested and maintained by one developer. Your support keeps these guides accurate and ad-light.
Buy me a coffee

Comments

Leave a reply