Personal Catalogue: PHP & MySQL — Chapter 10, Exercise 1
====================================================
TASK
Add the nginx location /catalogue/ block from this chapter to a real
(or test) nginx config, alongside a real static index.html served at
the site root. Confirm both example.com/ (or your test domain) and
example.com/catalogue/index.php resolve correctly to their own
separate real content.
SOLUTION
1. Create a minimal static file for the site root:
echo "
Main Astro Site (test)
" > /var/www/example.com/dist/index.html
2. Confirm the catalogue project already exists at /var/www/catalogue/
from earlier chapters (with a real index.php that outputs
something identifiable, e.g. "Catalogue
").
3. Add the full server block from the chapter to a real nginx site
config (e.g. /etc/nginx/sites-available/example.com), adjusting
server_name to your real test domain or IP, and the PHP-FPM socket
path to match your actual installed PHP version.
4. Test the config and reload nginx:
sudo nginx -t
sudo systemctl reload nginx
5. Visit both URLs:
https://example.com/ -> shows "Main Astro Site (test)"
https://example.com/catalogue/index.php -> shows "Catalogue"
Both should load correctly, each serving its own real, separate
content, confirming the location /catalogue/ block correctly routes
only requests under that path to the PHP-FPM backend, while every
other request falls through to the static root.
A useful negative check: confirm example.com/catalogue/ (with no
index.php in the URL) also resolves correctly, since index.php inside
the location block should be picked up automatically as the directory
index — proving the index.php directive inside the nested location is
actually working, not just the explicit .php request.
WHY THIS WORKS AS AN ANSWER
----------------------------
It sets up a genuine, minimal but real test of both paths (root and
mounted) rather than only checking the mounted path in isolation, and
adds a specific check (the bare /catalogue/ URL with no filename) that
verifies the nested location's own index directive is actually doing
its job, not just that PHP-FPM is reachable at all.