Beginner · 8 min · practise every command in the built-in terminal

nginx — Your First Web Server

A web server answers requests from browsers: someone asks for a page, the server sends it back. nginx (say "engine-x") serves a large part of the web, and on Debian it's one command away.

Install it

sudo apt update
sudo apt install nginx

Debian starts nginx as soon as it's installed, and enables it so it starts again after a reboot:

systemctl status nginx
systemctl is-enabled nginx

Ask it for a page

curl is a browser for the terminal — it prints the page instead of drawing it:

curl localhost          # the page's HTML
curl -I localhost       # only the response headers

HTTP/1.1 200 OK means here it is, and Server: nginx/1.26.3 tells you who answered. localhost is this machine itself.

Who listens on port 80?

Web servers wait for visitors on port 80 (http) and 443 (https):

sudo ss -tlnp | grep :80
ps aux | grep nginx

There's one master process (root, it opens the port) and worker processes that do the work as the unprivileged user www-data — if a worker is ever tricked, it can't touch the rest of the system.

Where things live

PathWhat's there
/etc/nginx/nginx.confthe main configuration
/etc/nginx/sites-available/one file per site
/etc/nginx/sites-enabled/links to the sites that are switched on
/var/www/html/the files of the default site
/var/log/nginx/access.log (every request) and error.log

💡 Only one program at a time can listen on a port. If nginx won't start because of Address already in use, another program already has port 80 — sudo ss -tlnp shows which one.

Practice tasks

  1. Install the nginx web server
  2. Check that nginx is running
  3. Fetch the welcome page from your server
  4. Look at only the response headers — who answered?
  5. Find the program listening on port 80

Commands in this lesson

Web Server (nginx)