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.
A fresh Droplet is built from an image that’s already a few weeks old. So the first thing we do is update it. Then we install Nginx, the web server that will sit in front of everything.
APT is Ubuntu’s package manager. It keeps two things separate: the list of packages available and the packages installed. apt update refreshes the list. apt upgrade installs the newer versions it found.
Update, then install
In your deploy session, run:
sudo apt update
apt list --upgradable
sudo apt upgrade
sudo apt install nginx
Read the list apt upgrade proposes before you press y. If it says some packages were “kept back”, that’s usually Ubuntu’s phased updates rolling out gradually. Leave them. Don’t force individual versions to make the message go away.
Verify in layers
An installed package, a valid configuration and a running service are three different things. Check each one:
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
Here’s what you want to see. nginx -v prints the version. nginx -t prints syntax is ok and test is successful. The two systemctl calls print enabled and active: the service runs now and will start at boot. ss shows a process listening on 0.0.0.0:80. The last command returns HTTP/1.1 200 OK and the response headers of the default welcome page.
I do the layered check every time, even when everything looks fine. A running service says nothing about the firewall. An installed package says nothing about its configuration. When something breaks later, you’ll know which layer to blame.
Two things that go wrong
If apt says Could not get lock /var/lib/dpkg/lock-frontend, another package operation is running. On a new Droplet that’s almost always the automatic updater doing its first pass. Wait a minute and try again. Never delete the lock file while apt or dpkg is running.
If Nginx fails to start, look at the evidence before reinstalling anything:
sudo systemctl status nginx --no-pager
sudo journalctl -u nginx -b --no-pager
sudo nginx -t
You’ll find a syntax error, a missing file or another process already on port 80. Fix that, then sudo systemctl restart nginx.
Save the successful nginx -t, is-active, ss and curl output in your notes. The request from the outside world comes in the next lesson, after we open the web ports on purpose.
Lesson completed