Start, Reload, and Stop the Exercise Instance
🎯 Introduction
Passing the configuration check does not start the service. You also need to know how to apply later changes. This article distinguishes configuration saved on disk from configuration used by the running instance.
🛠 Start and Verify the Instance
Confirm that the files from the preceding two articles are in place, then run these commands in the same terminal:
ngx -t
ngx
curl -i http://127.0.0.1:8080/
Run the second command only if the first check passes. Nginx runs in the background by default, so successful startup usually prints nothing. The third command performs the actual verification.
curl sends an HTTP request; -i displays both response headers and the body. You should see HTTP/1.1 200 OK, a header such as Content-Type: text/html; charset=utf-8, and “My Study Notes”. You can open the same address in an Ubuntu desktop browser. On a remote exercise machine, 127.0.0.1 refers to that remote machine, so verify from its terminal first.
Try an address that does not exist:
curl -i http://127.0.0.1:8080/missing.txt
Expect 404 Not Found: the request reached Nginx, but no content was found. This differs from “connection refused”, which usually means no service is accepting connections at that address and port.
🧱 How Changes Take Effect
If you change only the text in html/index.html, Nginx can serve the new content the next time it reads the file. A reload is usually unnecessary. Browser caching can cause stale content; that comes later.
If you change a .conf file, the master process must read it again:
ngx -t && ngx -s reload
&& runs the second command only if the first succeeds. reload starts workers with the new configuration and lets old workers finish existing requests before exiting. This is a graceful reload. Successfully sending the reload signal does not prove that every feature works. Request the target URL again and check logs/error.log if necessary.
Do not repeatedly run ngx without arguments to apply configuration. That attempts to start another instance and often produces address already in use, meaning the port is occupied. See the official control documentation.
🧰 Stop, Restart, and Inspect Configuration
ngx -s quit
quit performs a graceful shutdown, waiting for active requests to finish. Requests should fail to connect after shutdown. Run ngx -t and ngx again to start the instance. -s stop performs a fast shutdown; prefer quit for routine exercises.
If you are unsure which files are being read, run:
ngx -T
-T checks and prints the current configuration on disk, including included files, which helps confirm paths. It does not read the configuration currently held in memory or indicate that a reload has occurred. Configuration may contain internal addresses and other information; inspect the output before sharing it.
❓ Questions and Answers
Q1: What if logs/nginx.pid cannot be found?
Confirm that this instance has started and that ngx points to the same directory. Do not fill in the file with the system instance's process ID. If this instance has not started, check the configuration and start it normally.
Q2: Can systemctl reload nginx replace ngx -s reload?
Not in this course. systemctl manages the package's system service, not our separate instance.
🧪 Exercise
Add “I completed my first deployment” to the home page, save it, and verify it with curl. Then add client_max_body_size 2m; inside server, check the configuration, and reload.
Check your result: explain that the first change modified a content file while the second modified configuration. The home page should still return 200. Request body limits are explained later; for now, this directive is just practice in applying configuration changes.
🎉 You have completed the full cycle of checking, starting, requesting, and reloading!
