Serve the Web

Update Ubuntu and install Nginx

Apply the first updates, install the web server from Ubuntu repositories, and verify both the package and service state.

8 minute lesson

~~~

APT separates available-package information from installed packages. apt update refreshes the package index. apt upgrade reviews and installs newer versions for the current Ubuntu release.

Keep the working SSH session open and run:

sudo apt update
apt list --upgradable
sudo apt upgrade
sudo apt install nginx

Read the proposed upgrade before confirming it. A message about packages being kept back can be normal during Ubuntu phased updates. Do not work around it blindly by forcing individual versions.

Now verify the package, configuration, and service separately:

nginx -v
sudo nginx -t
systemctl is-enabled nginx
systemctl is-active nginx
sudo ss -lntp | grep -E ':80\s'
curl -I http://127.0.0.1

nginx -t should report successful syntax and file checks. The service should be enabled and active. ss should show a listener on port 80, and the local request should return an HTTP response such as 200 OK.

This layered check matters. A running service does not prove the firewall permits traffic. A package being installed does not prove its configuration is valid.

If APT says another process holds its lock, check whether automatic updates are still running. Wait for the real package operation to finish. Do not delete lock files while APT or dpkg is active.

If Nginx fails to start, inspect evidence before reinstalling it:

sudo systemctl status nginx --no-pager
sudo journalctl -u nginx -b --no-pager
sudo nginx -t

A syntax error, missing file, or occupied port will usually appear there. Fix that cause and run sudo systemctl restart nginx.

Your action is to collect the successful nginx -t, is-active, listening-port, and local HTTP results. The public request comes after we deliberately open the web ports.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →