SKDBLOG

DevOps

Install Nginx on Ubuntu Server: apt, UFW, systemd, welcome page

Install nginx with apt on Ubuntu Server, punch holes for HTTP or HTTPS through UFW, prove systemd keeps the unit active running, then sanity-check the default welcome page from your public IP before you chase TLS or proxy wiring.

Shashikant Dwivedi
5 min read
Install Nginx on Ubuntu Server: apt, UFW, systemd, welcome page
DevOps05 MIN

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? Grab the Nginx on Ubuntu install and firewall snippet — one bash slab with apt plus UFW so you skip the narration.

At a glance: the five moves
  1. Refresh system packages.
  2. Install the nginx package.
  3. Allow Nginx Full in UFW (ports 80 and 443).
  4. Confirm the service is active (running).
  5. Open your server’s public IP in a browser and see the default welcome page.

What you accomplish on this Ubuntu server

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 nginx then sudo systemctl enable --now nginx
  • Amazon Linux 2 (yum): sudo amazon-linux-extras install nginx1 or use the nginx package from your AMI’s repos, then sudo systemctl enable --now nginx

Firewall tools differ (firewalld, iptables, or only cloud SGs). Allow HTTP/HTTPS the way your distro documents.

What Nginx does as a web server and proxy

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. Once this baseline install works, proxying to upstream ports is the natural next chapter — still boring nginx reload and firewall hygiene, just more server { ... } blocks.

Learn more (official and docs)

Install Nginx step by step

If you already keep /snippets/nginx-ubuntu-install-commands pinned beside database installs or cron posts, treat this section as the annotated companion — same cadence, just slower narration.

Step 1 — Update packages

Refreshing the package index (and upgrading installed packages) reduces “weird install” issues from stale metadata.

bash
sudo apt-get update && sudo apt-get upgrade

Step 2 — Install Nginx

This installs the server binary, default site config, and systemd service.

bash
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.

bash
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.

bash
sudo systemctl status nginx

Verify the default welcome page in a browser

  1. Copy your server’s public IP from your cloud provider (or run curl -4 ifconfig.me from the server if outbound HTTP is allowed).
  2. 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).

Frequently asked questions

Do I need both UFW and my cloud security group to allow HTTP?

Yes on almost every VPS pattern you rent today: UFW enforces policy on the Linux box itself while security groups / VPC ACLs answer first at the hypervisor edge. Open TCP 80 (and 443 once HTTPS terminates here) in both places or curls from your laptop stall even though sudo systemctl status nginx looks healthy.

Should I use the Nginx Full or Nginx HTTP UFW profile?

Pick Nginx Full when you already expect Let’s Encrypt or another TLS workflow soon — it grants 80 + 443 in one shot. Stay on Nginx HTTP only if you deliberately want plaintext listeners until DNS and certs exist; either way Certbot plus Nginx later assumes those ports remain reachable.

How do I confirm nginx is running with systemd?

Run sudo systemctl status nginx and read the Active line first. Follow up with sudo journalctl -u nginx -e --no-pager when boot logs explain failures faster than sudo nginx -t. Those checks mirror what people automate after grabbing /snippets/nginx-ubuntu-install-commands.

Where does the default welcome page load from on Ubuntu?

Packages ship a stock server stanza pointing web roots at /var/www/html. Swap files there only after you graduate past the bundled landing HTML — production setups usually introduce sites-available snippets instead.

Is there a copy-paste command list without the explanations?

Yes — open the snippet slab whenever you want apt-and-UFW lines without prose.

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 in sites-available) for your domain and reload Nginx — reverse-proxy recipes on this blog reuse the same reload cadence you practiced above.
  • Comparison curiosity: When .htaccess ergonomics beat proxy purity for a workload, skim Apache on Ubuntu EC2 after this nginx baseline so both stacks stay mentally comparable.
  • Troubleshooting: sudo nginx -t validates config before reload; check error.log under /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.

All writing →

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.