DevOps
How To Install And Configure Nginx On Your Linux Server
Install Nginx on Ubuntu, open the firewall, and confirm the welcome page—step by step, with copy-paste commands and quick checks along the way.
Shashikant Dwivedi
This guide walks you through installing Nginx on an Ubuntu server, allowing HTTP through the firewall, and confirming everything in the browser. Work through the steps in order; each block tells you why you are running a command, not only what to paste.
Only need the commands? Use the snippet Nginx on Ubuntu — install and firewall commands — one copy-paste block, no explanations.
At a glance: the five moves
- Refresh system packages.
- Install the
nginxpackage. - Allow Nginx Full in UFW (ports 80 and 443).
- Confirm the service is active (running).
- Open your server’s public IP in a browser and see the default welcome page.
What you will accomplish
By the end you will have:
- A running Nginx web server listening on the usual HTTP port.
- UFW rules so browsers can reach Nginx from the internet (for typical cloud setups).
- A simple sanity check: the default Nginx page loads when you visit the server’s public IP.
Before you start
- Ubuntu (or another Debian-based distro using
apt). The commands below target Ubuntu; other families use different package managers (see the expandable note below). - SSH access with
sudo(for example, an EC2 instance and its public IP). - Optional but useful: note your instance’s public IPv4 from the cloud console before you open the browser test.
Not on Ubuntu? (RHEL, Fedora, Amazon Linux)
Rough equivalents:
- RHEL / Rocky / Alma (dnf):
sudo dnf install nginxthensudo systemctl enable --now nginx - Amazon Linux 2 (yum):
sudo amazon-linux-extras install nginx1or use thenginxpackage from your AMI’s repos, thensudo systemctl enable --now nginx
Firewall tools differ (firewalld, iptables, or only cloud SGs). Allow HTTP/HTTPS the way your distro documents.
What is Nginx?
Nginx is open-source software often used as a web server or reverse proxy. It serves static files efficiently and sits in front of app servers in many production stacks.
Learn more (official and docs)
- Project home: nginx.org
- Admin guide: nginx documentation
Step-by-step installation
Step 1 — Update packages
Refreshing the package index (and upgrading installed packages) reduces “weird install” issues from stale metadata.
sudo apt-get update && sudo apt-get upgrade

Step 2 — Install Nginx
This installs the server binary, default site config, and systemd service.
sudo apt install nginx

Step 3 — Allow Nginx through UFW
ufw is Ubuntu’s friendly front end to the firewall. Nginx Full opens 80 (HTTP) and 443 (HTTPS), which saves you a second pass when you later add TLS.
sudo ufw app list
sudo ufw allow 'Nginx Full'
If you only want HTTP for now, you can use sudo ufw allow 'Nginx HTTP' instead.

Step 4 — Check that Nginx is running
systemctl status shows whether the unit is active, recent log lines, and whether it will start on boot.
sudo systemctl status nginx

Verify in the browser
- Copy your server’s public IP from your cloud provider (or run
curl -4 ifconfig.mefrom the server if outbound HTTP is allowed). - Paste it into a browser address bar (
http://YOUR_IP).
You should see the default “Welcome to nginx!” page served from /var/www/html (default install).

What next?
- TLS: Once you have a domain pointing at this server, follow a Let’s Encrypt workflow—for example the Certbot + Nginx guide on this site.
- Real sites: Add a
server { ... }block (or a file insites-available) for your domain and reload Nginx. - Troubleshooting:
sudo nginx -tvalidates config before reload; checkerror.logunder/var/log/nginx/if something refuses to start.
If you hit a snag, note your Ubuntu version, the exact systemctl status line, and any nginx -t output—that makes it much easier to narrow down.

Written by Shashikant Dwivedi
Engineer, occasional writer, full-time noticer. Based in Prayagraj, India. New essays land roughly twice a month.
Keep reading
Adjacent essays.

DevOps
Setting Up Nginx as a Reverse Proxy - The Easy Way! 🚀
Oct 25, 2024 · 2 min

DevOps
Getting Free SSL Certificates with Certbot - The No-Stress Guide! 🔒
Oct 26, 2024 · 3 min

DevOps
🚀 PostgreSQL Installation Guide for Ubuntu: Your Complete Walkthrough!
Jan 1, 2025 · 2 min
The newsletter
New articles in your inbox.
Occasional articles on engineering, tooling, and software development practices. No marketing, no fluff — just the article, when it's ready.
Unsubscribe with one click. Your email never leaves the list.