How To Install Nginx On Ubuntu 25.04 (Step-By-Step Guide For 2025)

How To Install Nginx On Ubuntu 25.04 (Step-By-Step Guide For 2025)

Here is a clear, step-by-step guide to install Nginx on Ubuntu 25.04 :

🔧 1. Update APT and Install Nginx

Since Ubuntu 25.04 includes Nginx in its default repositories, start with :

sudo apt update  
sudo apt install nginx -y

Then check the installed version :

nginx -v
# Expect something like: nginx version: nginx/1.26.3 (Ubuntu)

⚙️ 2. Manage the Nginx Service

Control the Nginx systemd service with :

sudo systemctl start nginx     # Start service now
sudo systemctl enable nginx    # Auto-start at boot
sudo systemctl status nginx    # Check running status

To restart or stop :

sudo systemctl restart nginx
sudo systemctl stop nginx

✅ 3. Verify Installation & Default Page

Open your browser and enter :

http://<server_IP_or_domain>

You should see the default Nginx "Welcome" page.

Alternatively :

curl -I 127.0.0.1
# Expect 200 OK from nginx

🛡️ 4. (Optional) Use Official Nginx Repository

If you want the latest stable or mainline Nginx (beyond the Ubuntu repo version), consider adding Nginx's official APT repo :

http://<server_IP_or_domain>

Add prerequisites and signing key :

sudo apt update
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring -y

curl https://nginx.org/keys/nginx_signing.key \
  | gpg --dearmor \
  | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Add the repository (choose branch) :

# For stable:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" \
  | sudo tee /etc/apt/sources.list.d/nginx.list

# For mainline (cutting-edge):
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu $(lsb_release -cs) nginx" \
  | sudo tee /etc/apt/sources.list.d/nginx.list

Prioritize official repo :

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900" \
  | sudo tee /etc/apt/preferences.d/99nginx

Finally, install via nginx.org repo :

sudo apt update
sudo apt install nginx -y

📝 5. Post-Installation Tips

  • Firewall (UFW) : if active, allow web traffic :
sudo ufw allow 'Nginx HTTP'
# For HTTPS also:
sudo ufw allow 'Nginx Full'
  • Web Root: Default files live under /var/www/html/. You can create server blocks in /etc/nginx/sites-available/ and symlink them in sites-enabled/, then reload Nginx :
sudo systemctl reload nginx

✅ Summary

|-------------------------------------  | ------------------------------------------------------------|
| Step                                  | Command(s)                                                  |
| ------------------------------------- | ----------------------------------------------------------- |
| 1. Install                            | sudo apt update && sudo apt install nginx -y                |
| 2. Start & Enable                     | sudo systemctl start nginx && sudo systemctl enable nginx   |
| 3. Verify                             | nginx -v, browse to IP, or curl -I 127.0.0.1                |
| 4. (Optional) Add official repo       | Add key, repo, pin, then 'apt update && apt install nginx'  |
| 5. Configure firewall & virtual hosts | UFW rules and 'sites-available' setup                       |
|-------------------------------------  | ------------------------------------------------------------|

Tags :