Server foundations

Install and inspect Nginx

Install Nginx from Ubuntu packages and verify the package, service, listener, and first HTTP response.

8 minute lesson

~~~

Nginx is a web server and reverse proxy. It sits in front of your files and your applications, and it handles the raw HTTP traffic from the internet.

On Ubuntu, install it through APT so package updates and systemd integration remain visible to the server administrator:

sudo apt update
sudo apt install nginx

The package puts the configuration under /etc/nginx/, installs a systemd unit, and starts the service right away with a default welcome page.

Now prove it’s actually working. I use three checks, and I run them in this order because each one tests a different layer.

Is the service running?

systemctl status nginx

Look for active (running) in the output. This tells you systemd started the process and it didn’t crash. It says nothing about the network yet.

Is something listening on port 80?

sudo ss -lntp | grep nginx
# LISTEN 0  511  0.0.0.0:80   0.0.0.0:*  users:(("nginx",pid=1204,fd=6),...)

ss -lntp shows listening TCP sockets with the owning process. You want an nginx entry bound to port 80. Note the PID and the address: 0.0.0.0 means it accepts connections on every network interface.

Does it answer HTTP?

curl -I http://127.0.0.1
# HTTP/1.1 200 OK
# Server: nginx/1.24.0 (Ubuntu)

curl -I http://127.0.0.1 sends a real request and prints only the response headers. A 200 OK from Server: nginx closes the loop: the service runs, the socket is open, and HTTP works end to end.

Keep these three checks separate in your head. A running service with no listener points at a configuration problem. A listener that never answers points at a firewall or a hung process. When something breaks later, the first check that fails tells you where to look.

The most common installation failure is a port conflict. If Apache or another server already owns port 80, Nginx refuses to start, and journalctl -u nginx shows a line like bind() to 0.0.0.0:80 failed (98: Address already in use). Stop the other server or change the listen port, then start Nginx again.

Run the three checks on a disposable Ubuntu server. Record which process listens, which address and port it uses, and the returned status code.

Lesson completed

Take this course offline

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

Get the download library →