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 4 of 7 · on a machine · 6 min

From a page address to a file

The block is chosen; now nginx looks for the file. This step shows how a page address turns into a path on disk.

In the address http://docs.lab.test/guide/install.html, the part after the site name is the page path, the URI: /guide/install.html. nginx appends it to the chosen block's root: /srv/www/docs and /guide/install.html give /srv/www/docs/guide/install.html. If the URI ends in /, nginx looks in that directory for the file named in the index directive: that is how / on the portal gives /srv/www/portal/index.html.

No file means a 404 Not Found answer. nginx writes the reason to its error log, /var/log/nginx/error.log: which path it tried to open and which block handled the request. The log is open to nginx and the adm group, so read it with sudo.

Back to the original breakage: the docs site is not enabled again, and a user opens the link to the installation guide.

Exercise · look

Open the guide by its link

The docs site is not enabled again. Request the guide at http://docs.lab.test/guide/install.html, then read the last line of the nginx error log.

First, predict

Which file will nginx try to open for this address?

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
Ubuntu 24.04
Loading…