generated from nhcarrigan/template
1.3 KiB
1.3 KiB
NGINX Configs — Project Notes
404 Handling
Global 404 redirect
Any 404 from any site is handled globally via nginx/nginx/nginx.conf in the http {} block:
error_page 404 https://404.nhcarrigan.com;
This redirects (302) to 404.nhcarrigan.com which serves /home/naomi/404/index.html.
No need to add error_page to individual server blocks — the http {} level default covers everything.
404 site config
nginx/nginx/sites-available/404.conf — serves the static 404 page at /home/naomi/404.
Requires an SSL cert at /etc/letsencrypt/live/404.nhcarrigan.com/.
Catch-all server block (catch-all.conf)
Handles any HTTPS request for a subdomain that doesn't match any configured server_name.
Uses default_server on port 443, server_name _, and serves the same 404 page directly
(with return 404 to preserve the status code, since this is the final fallback rather than a redirect).
Adding a New Site
- Create
nginx/nginx/sites-available/<name>.confwith the server block. - Create a symlink:
ln -s ../sites-available/<name>.conf nginx/nginx/sites-enabled/<name>.conf - Ensure an SSL cert exists on the server for the domain (
certbot --nginx -d <domain>). - No need to add
error_page 404— it's handled globally.