Run your first isolated Nginx web server
A first server without changing system configuration
This optional lab serves one HTML file on the local loopback address. It uses a dedicated directory, separate PID and logs, and a high port. The core lesson works offline: read the fixture and predict its behavior. Execute only in an approved disposable Linux VM or suitably isolated container, as a normal unprivileged user, using a supported patched Nginx installation and curl. Do not use a live host, shared service, real data or a public port.
Prepare the files
Extract the package. In the lab-fixtures/chapter-02 directory, you will find nginx.conf and html/index.html. The following commands create a fresh private working directory and copy those reviewed files. Keep the same shell open so the LAB variable remains available.
# From the extracted archive's lab-fixtures/chapter-02 directoryLAB=$(mktemp -d)mkdir -p "$LAB/html" "$LAB/logs" "$LAB/temp"cp nginx.conf "$LAB/nginx.conf"cp html/index.html "$LAB/html/index.html"printf 'Lab directory: %s\n' "$LAB"worker_processes 1;pid logs/nginx.pid;lock_file logs/nginx.lock;error_log logs/error.log notice;events { worker_connections 32; }http { access_log logs/access.log; client_body_temp_path temp/body; proxy_temp_path temp/proxy; fastcgi_temp_path temp/fastcgi; uwsgi_temp_path temp/uwsgi; scgi_temp_path temp/scgi; types { text/html html; } server { listen 127.0.0.1:18080; server_name localhost; root html; index index.html; }}The PID file records the master process identifier; the master coordinates worker processes, which handle requests. The log and temporary directories remain inside the lab. worker_connections bounds the number of simultaneous connections per worker; that is not a count of simultaneous users. http contains web configuration, server describes one virtual server, and listen binds only the IPv4 loopback address on port 18080. root html maps files under the lab prefix, while index names the default index file. The types block tells Nginx to send .html files with an HTML media type. Full directive grammar comes next.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Local reading room</title> </head> <body> <h1>Reading room is open</h1> </body></html>Check, start and request
First confirm that port 18080 is unused in the disposable environment (for example with ss -ltn if installed). If another process owns the port, stop the exercise or choose another high port consistently; never stop an unrelated process. Test the known configuration before starting. Even a syntax test opens referenced files, so do not point it at arbitrary configurations.
A successful test is expected to report that the configuration syntax is valid and the test succeeded. This does not establish that the server can actually bind the port or answer requests. If it fails, read the diagnostic and correct the lab files before proceeding.
nginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf"The default daemon mode normally returns control to the shell. The master writes its PID to logs/nginx.pid under the selected prefix. The default system service remains untouched. If the command fails, read the lab error log; never switch to sudo as a generic solution.
curl --noproxy "*" --max-time 3 -i http://127.0.0.1:18080/index.htmlHTTP/1.1 200 OKContent-Type: text/html...<h1>Reading room is open</h1>The status indicates success, the media type tells the client how to interpret the bytes, and the heading comes from the file. The omitted headers vary. Requesting /missing.html should return 404 in this fixture if the file does not exist. A refused connection means no HTTP response was received; inspect the listener and lab error log before assuming a file is missing.
Reload and stop the same instance
For a configuration change, save the old file, edit only the lab copy, rerun the exact test, then reload the same lab master. Verify a new request and inspect logs/error.log; a successful signal does not prove a successful reconfiguration. A simple HTML file edit does not require a configuration reload. Only use the signal commands after confirming the lab PID belongs to the process you started and the isolated instance is still active.
nginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf" -s reloadnginx -e stderr -p "$LAB/" -c "$LAB/nginx.conf" -s quitGraceful quit allows active requests to finish. Check that the process has exited and the listener is gone before removing any lab-owned files. You can retain the directory for inspection; there is no broad cleanup command. If the server was never started, skip signaling it. A production service has different operational procedures.
Do not edit /etc/nginx, run systemctl restart nginx, change host permissions or expose the listener on all interfaces. Keep every path and process inside the approved disposable environment.
Offline practice
Predict the result of a request to /index.html and /missing.html. Identify the path that serves the first file, the listener address, the PID file and the log used to diagnose a failed startup. Then explain why a passing configuration test alone cannot prove that either response is correct.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
First isolated server
Check the main concepts taught in this lesson.
Who can normally connect to a listener bound to 127.0.0.1 in the lab?
A configuration test succeeds. Which claim is justified?
What is the expected status for /missing.html in the fixture?
Which file helps the signal command locate the intended master?
You edit only the HTML page in this simple fixture. What is normally needed to see the new text?