Case File: The Public Page
Sabi Logistics is putting a parcel-tracking page on the internet and the first nginx config will not even start. Fix it so the right site is served from the right folder, visitors cannot browse the files, hidden files stay hidden and the server does not announce its version. The configuration is generated for you alone.
Sabi Logistics · Case 1
The Public Page
A page for thousands of customers goes live today, and it must not leak the company's files
Ngozi Lead developer · Phone call
Ngozi. The tracking page is finished and the files are on the server. Chidi wants it public by lunchtime, and I have never written an nginx config in my life, so I copied one from a forum post. nginx refuses to start with it.
I do not only want it working. I want it so that when someone nasty looks at it, there is nothing to find. Can you sort out the config properly?
The brief
What you need to know first.
- A server block is one website. nginx picks it by the port in
listenand the name inserver_name. rootsays which folder holds the files.indexsays which file is the front page.location / { try_files $uri $uri/ =404; }means: serve the file if it exists, the folder’s index if it is a folder, otherwise a clean 404.autoindex on;turns on directory listings. Strangers find old backups that way. Leave it off.- Files whose names start with a dot (
.git,.env) often hold secrets. Block them. server_tokens off;stops nginx announcing its exact version to every visitor.- Every directive ends with a semicolon, and every
{needs its}. One missing character and nginx will not start. Always runnginx -tbefore you reload.
Edit the file below until every requirement is met. The checker reads the file the way nginx would: it does not care about spacing or the order of lines that do not depend on each other.
The flag: when everything is met your change ticket reference appears. Submit it at the bottom of the page.
Preparing the server…
Ngozi, an hour later: “It is live and it looks great. Chidi has just asked me for the real error logs for this site separately from the other ones, because the marketing site is on the same server and its logs are drowning everything. And he asked why the page says ‘Not secure’. I thought you fixed it?”
🔒 The debrief unlocks when you close the case. Finish the lab above.
The debrief
Ngozi: “Right, so it was working, but it was not finished. I get that now.”
What a senior engineer would do next. Give every site its own log files from day one, so the one you need is never buried under another. Check from outside the server, not just inside it: curl -I for the headers and a request for /.env to prove it is refused. Keep the configuration in version control so every change is reviewed and can be undone. And plan the certificate straight away, because a site that takes any kind of login must not run over plain HTTP. That is the next case.
The ideas to keep.
- The file is read by a strict parser. One missing semicolon stops everything, so test with
nginx -tbefore every reload. - Say what you serve, and nothing else. A directory listing, a version number and a reachable
.envare all free gifts to an attacker. - A 404 should be a clean 404.
try_files ... =404means unknown paths never fall through to something surprising. - One site, one log. It is the first thing you will want at 3 a.m.
Next case: the padlock.
Write the change note
Write what you changed in this configuration and why: the folder and names it serves, what you switched off or blocked and the reason for each, and how you would test it on the real server before and after the reload.
🧪 Want to practise this on your own computer? See how to set up your lab →