Learn how to install Nginx on Ubuntu 26.04 with this easy step by step guide. Install Nginx, configure a server block, allow firewall access, and verify your web server is running in minutes.
Nginx is one of the most popular web servers in the world. It is fast, lightweight, and can handle thousands of connections with very little memory. Whether you're hosting a website, running a reverse proxy, or deploying applications, Nginx is a reliable choice for Ubuntu servers.
Prerequisites
Before you begin, make sure you have:
-
A server running Ubuntu 26.04 dedicated server.
-
A user with sudo privileges
-
An internet connection
Learn how to install Nginx on Ubuntu 26.04
Step 1: Update the Package List
First, update your package index so Ubuntu knows about the latest available packages.
sudo apt update
Keeping the package list updated helps avoid installation issues and ensures you install the latest version available in the Ubuntu repositories.
Step 2: Install Nginx
Install Nginx using the following command:
sudo apt install nginx -y
The installation usually takes less than a minute depending on your internet speed. Ubuntu automatically installs any required dependencies during this process.
Step 3: Verify the Installation
After the installation finishes, check the installed version.
nginx -v
Example output:
nginx version: nginx/1.xx.x
The exact version may be different depending on the latest package available for Ubuntu 26.04.
Step 4: Check the Nginx Service
Ubuntu starts the Nginx service automatically after installation.
Verify its status by running:
sudo systemctl status nginx
If everything is working correctly, you'll see something similar to:
Active: active (running)
Press Q to exit the status screen.
Step 5: Enable Nginx at Boot
Although Nginx is usually enabled automatically, it's a good idea to confirm.
sudo systemctl enable nginx
This ensures Nginx starts automatically every time your server reboots.
Step 6: Allow HTTP and HTTPS Through the Firewall
If you're using UFW, allow web traffic.
Allow HTTP:
sudo ufw allow 'Nginx HTTP'
Or allow both HTTP and HTTPS:
sudo ufw allow 'Nginx Full'
Check the firewall status:
sudo ufw status
You should see rules allowing ports 80 and 443.
Step 7: Test Nginx
Find your server's public IP address.
hostname -I
Example:
203.0.113.25
Open your browser and visit:
http://YOUR_SERVER_IP
If Nginx is installed correctly, you'll see the default Welcome to nginx! page. This confirms your web server is working properly.
Add this section after "Where Nginx Files Are Located" and before "Uninstall Nginx".
Step 8: Create Your First Nginx Server Block
A server block tells Nginx which website to serve and where the website files are stored.
Create a new configuration file:
sudo nano /etc/nginx/sites-available/example.com
Replace the contents with the following configuration:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
}
Replace example.com with your own domain name.
Next, create the website directory:
sudo mkdir -p /var/www/example.com/html
Create a simple test page:
echo "<h1>Welcome to Nginx</h1>" | sudo tee /var/www/example.com/html/index.html
Enable the website by creating a symbolic link:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Check the Nginx configuration for errors:
sudo nginx -t
If the test is successful, reload Nginx to apply the changes:
sudo systemctl reload nginx
If your domain's DNS records point to your server, opening http://example.com in a browser should display the test page you created. Humans invented symbolic links just to make enabling websites feel mysterious, but fortunately this is one of the few Linux rituals that actually makes sense.
Useful Nginx Commands
Start Nginx
sudo systemctl start nginx
Stop Nginx
sudo systemctl stop nginx
Restart Nginx
sudo systemctl restart nginx
Reload Configuration
sudo systemctl reload nginx
Reloading applies configuration changes without interrupting active connections.
Check Service Status
sudo systemctl status nginx
Check the Configuration Before Reloading
Whenever you edit an Nginx configuration file, test it before restarting the service.
sudo nginx -t
If everything is correct, you'll see output similar to:
syntax is ok
test is successful
This simple check can save you from downtime caused by configuration mistakes.
Where Nginx Files Are Located
| File or Directory | Purpose |
|---|---|
/etc/nginx/ | Main configuration directory |
/etc/nginx/nginx.conf | Main configuration file |
/etc/nginx/sites-available/ | Available website configurations |
/etc/nginx/sites-enabled/ | Enabled websites |
/var/www/html/ | Default website directory |
/var/log/nginx/access.log | Access log |
/var/log/nginx/error.log | Error log |
Uninstall Nginx
If you no longer need Nginx, remove it with:
sudo apt remove nginx -y
To remove configuration files as well:
sudo apt purge nginx -y
Finally, remove unused packages:
sudo apt autoremove -y
Conclusion
In this tutorial, we have learnt how to install Nginx on Ubuntu 26.04 only takes a few minutes. After installation, your server is ready to host websites, run reverse proxies, or serve web applications. As your projects grow, you can add virtual hosts, enable HTTPS with SSL certificates, and fine tune Nginx for better performance and security.

