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 1 of 7 · on a machine · 5 min

The docs open the portal

What you will learn

  • Tell which server block will answer a request from the site name and the default server.
  • Enable a site with a link in sites-enabled and apply the configuration with nginx -t and reload.
  • Find the file nginx serves for a page address from root and the error.log line.

The server runs two company sites: the portal portal.lab.test and the docs docs.lab.test. nginx serves both. Users report that the docs address opens the portal.

Request both sites by name and see where these names lead. “Start” will set up the sites.

Exercise · look

Request both sites by name

Request the portal and the docs by their names, then see which address these names lead to.

First, predict

What will curl http://docs.lab.test/ print?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

Both names lead to 127.0.0.1. What does that mean for the two requests?

  • Both sites live on this machine, and 127.0.0.1 is the right address for docs: nginx answers there. The name is not the problem.

  • curl keeps nothing between runs: each run is a new connection, and curl -v shows it in the lines starting with *.

Both names lead to 127.0.0.1, so both requests reached one nginx on port 80, and it chose the page for each.

Ubuntu 24.04
Loading…