Linux Labs

Web stack / Stage 1 of 9

How nginx picks a site and a file

Not running Starting usually ~20 s
Leave the lesson

Step 6 of 7 · lab · 20 minmedium

Two sites on one nginx

The blog address opens the company site. Give each name its own site back without breaking the rest.

Situation

nginx on this server hosts two company sites: the main site www.lab.test and the engineering blog blog.lab.test. The blog recently moved to a name of its own. The main site's files live in /srv/www/main, the blog's in /srv/www/blog: the home page index.html and the archive archive.html. A request with a name that no site has gets 404.

The main site opens as usual. But http://blog.lab.test/ returns the main site's home page instead of the blog.

Both names are in /etc/hosts and point to this same machine, so you can run curl http://blog.lab.test/ right here.

Task

  1. blog.lab.test serves files from /srv/www/blog: the home page and /archive.html.
  2. www.lab.test serves files from /srv/www/main, as before.
  3. A request with an unknown site name gets 404.
  4. nginx is running, and its configuration passes nginx -t without warnings.

There is no internet on the machine; everything you need is already installed. Run administrative commands with sudo.

Lab · on your own

No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.

Goals

0 of 4
  • blog.lab.test serves files from /srv/www/blog — the home page and /archive.html — not done yet
  • www.lab.test serves files from /srv/www/main, as before — not done yet
  • A request with an unknown site name gets 404 — not done yet
  • nginx is running and its configuration passes nginx -t without warnings — not done yet
Ctrl+Enter
Starts the machine node1 · Ubuntu 24.04

The machine is starting

Hints

0 of 3

Lab goals

0 of 4
  • blog.lab.test serves files from /srv/www/blog — the home page and /archive.html — not done yet
  • www.lab.test serves files from /srv/www/main, as before — not done yet
  • A request with an unknown site name gets 404 — not done yet
  • nginx is running and its configuration passes nginx -t without warnings — not done yet
node1 Ubuntu 24.04

Lab goals

0 of 4
  • blog.lab.test serves files from /srv/www/blog — the home page and /archive.html — not done yet
  • www.lab.test serves files from /srv/www/main, as before — not done yet
  • A request with an unknown site name gets 404 — not done yet
  • nginx is running and its configuration passes nginx -t without warnings — not done yet
Loading…