Nginx safe reload, shutdown and log reopening
Test, reload, verify
A reload asks the existing Nginx master to adopt changed settings. With a normal successful reload, the master launches a replacement worker generation and lets the old generation finish serving existing work. This is different from stopping and starting the service. It reduces disruption but does not guarantee uninterrupted or correct application behavior.
These examples use the Chapter 4 disposable lab, not a system Nginx service. The optional commands require a reviewed patched Linux Nginx binary, unprivileged user, a private lab directory and an available loopback port. Expected outputs are predictions, not recorded executions. The lab serves a short text marker at /health. Before changing anything, save the original configuration and confirm that the original response is version-a. The lab README contains the preparation and start procedure.
cp "$LAB/nginx.conf" "$LAB/known-good.conf"cp "$LAB/version-b.conf" "$LAB/nginx.conf"nginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf" -tDo not proceed if the last command fails. Use the same binary, prefix, configuration and relevant startup options for test and control. Changing the PID path or using a different configuration can target the wrong instance.
nginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf" -s reloadThe command sends a control request; its successful exit does not prove that the master applied the new configuration. The master may reject new settings if a resource cannot be opened, leaving the previous workers serving. Old and new worker generations can briefly overlap. Check the lab error log and poll a bounded number of new requests until the intended response appears.
curl --noproxy '*' --max-time 2 -i http://127.0.0.1:18084/healthtail -n 20 "$LAB/logs/error.log"Expected after convergence: HTTP 200 and a body of version-b followed by a newline. A 200 response with version-a is not sufficient. A syntactically valid but wrong route can be activated successfully, so verify application behavior as well as logs. If a valid change behaves incorrectly, restore the saved file, test it, reload and verify that the original body returns.
cp "$LAB/known-good.conf" "$LAB/nginx.conf"nginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf" -t && nginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf" -s reloadThe && operator runs the second command only if the first exits successfully. It does not remove the need for post-reload HTTP checks. A failed master-side reload may preserve service but will not repair an incorrect file on disk.
Shutdown and log rotation
nginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf" -s quitQuit asks workers to drain active work before exiting; stop requests a faster shutdown that may interrupt work. Verify the owned process and listener have exited before cleanup. Reopening logs is a different operation: after an approved lab log rename, -s reopen requests that Nginx open its log paths again, without using a full configuration reload as a rotation mechanism.
nginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf" -s reopenOn Unix-like systems the conceptual mappings are reload → HUP, quit → QUIT, stop → TERM or INT for fast shutdown, reopen → USR1. Other master signals exist for advanced binary upgrades and worker control; they are outside this beginner lab. Do not signal arbitrary PIDs. When a systemd unit or another supervisor owns an instance, use its documented reload/stop behavior and authorization instead of manually controlling an unrelated process.
A restart can interrupt traffic and may fail to start if the configuration is invalid. Keep a reviewed rollback plan, inspect error logs, and verify application behavior. Graceful termination can take time; a configured worker shutdown timeout may close remaining connections.
Practice: decide when to roll back
The proposed configuration passes its test but the expected marker never appears. Identify what evidence to collect before rollback, and explain why a successful signal command alone is not enough. Complete the offline lab decision exercise before moving to static-site hosting.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Safe reload and shutdown
Check the concepts taught in this lesson.
The candidate fails nginx -t. What should you do?
What is expected on successful reload?
A reload command exits zero but the health marker is unchanged. What is the next step?
Which control request asks for graceful shutdown?
The new configuration is active but routes incorrectly. What is the safest lab rollback?