Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 8: Configuring Nginx and Apache

AWS Cloud

8.3 Task: change the Nginx document root

Suppose Mauli Dairy wants to serve its existing website from /var/www/portfolio. Locate the active rule for its hostname and prepare that directory first. The lab below uses the same release-change pattern with disposable local paths.

Check which site handles the hostname and where its current root is declared. Keep a verified backup of that file outside the include pattern, and prepare the new public content separately. In the selected site or location, the new root directive can be written as root /var/www/portfolio; when that is the approved content directory.

Preserve the listener, hostname and unrelated fallback site. Use the correct candidate configuration test and service activation for your installation. Verify both status and body with the intended hostname at the origin, then verify the normal browser route. The isolated exercise below uses its own process and shows the before, changed and restored responses.

On hosts that enforce SELinux, inspect the actual policy and file labels when a path is denied. A custom directory can need a persistent label mapping appropriate to the active service and policy. Distribution defaults and the labels on existing files vary. Ordinary directory traversal and file read permissions also need to be correct.

Never point the root at /root or /home/ec2-user

Use a dedicated tree that contains only files intended to be public. The worker identity needs search permission on the containing directories and read permission on the files, subject to host policy. Keep home directories, SSH material and other private files outside the public tree.

Ravindra Bagale's Tip

Because of a 403, many students do chmod 777 on their home folder and set the root to /home/ec2-user/site – that exposes your SSH keys and files. Always keep websites in /var/www or /srv and copy the files there.

Lab

Use the isolated lab below to change one site root, verify an independent site, restore the saved rule and check both releases with targeted HTTP requests.

A new release can use the same website address

Mauli Dairy has a small static website with a homepage and a downloadable list of products. Its address already appears on posters. The owner wants to publish a new design on the same address and keep the previous version ready to restore if the download does not work. Copying every file straight over the old site would make it difficult to tell which files belong to each release. Changing the DNS record would solve a different problem. The existing web server and the site's hostname can stay where customers expect them while Nginx starts finding this site's files under a different directory.

That starting directory is the document root. The Nginx root directive sets the starting point for ordinary static-file lookups in its effective context. A static file is ready-made content that the server can send directly, such as an HTML page, image or product list. If a request asks for /downloads/price-list.txt and the effective root is /srv/mauli/spring, the normal root mapping looks for /srv/mauli/spring/downloads/price-list.txt. When the root becomes /srv/mauli/summer, the same URL points to the corresponding path under the summer directory. The change is in the server's lookup rule. The customer can use the same link.

Keep four separate names in your notes. The hostname identifies the website among possible sites. The URL path identifies what the client wants from that site. The configuration file records the server's lookup instructions. The filesystem path identifies the file or directory on the machine. Changing a document root only affects the last step for routes that use that root. It does not copy files, add a listening port, enable a site, or make an application accept traffic. Before the change, make sure the new directory already has the files the site needs and that the actual virtual site reads the root declaration you intend to change.

Imagine three directories on the instance. The workshop spring release and workshop summer release each have a file named index.html and a subdirectory named downloads. A library site has its own homepage. The workshop's root points to the spring directory initially. You are asked to move that one root to summer and prove that the library continues using its own directory. If the spring page is still visible after the change, useful evidence includes which hostname you sent, which listener you reached, whether the candidate configuration was accepted, and whether display came from a cache. Finding the summer page on disk alone says nothing about whether anybody can get it at the intended URL.

This lesson uses an example release switch rather than a one-time setup of the welcome page. You can therefore test the change, restore the previous configuration and compare results meaningfully. The configuration discovery lesson shows how to establish the active entry and include path. The configuration reading lesson explains how address, hostname and URI select a rule. Together they answer the question to ask first, which root is responsible for the exact file path being tested?

Calculate the file path before opening an editor

Although a small server block can declare a root at the site level, a more specific block can supply another root. Consider a site with the default root under /srv/mauli/spring and a separate root under /srv/shared for /shared/. The first pricing path maps into the release. A request for /shared/policy.txt selects the shared prefix and ordinarily looks for /srv/shared/shared/policy.txt. The repeated name comes from appending the full request path to the named root. A reader who mentally removes the matching prefix would predict the wrong file and might grant access to an unrelated parent directory while troubleshooting.

An alias lets a suitable location replace the part of the path described by that location with another filesystem name. Suppose the location prefix is /forms/, the configured alias is /srv/registration/current/, and the URI is /forms/signup.txt. For that simple prefix mapping, the filesystem candidate is /srv/registration/current/signup.txt. The URL's forms prefix is replaced by the alias. With root, the same path would keep forms in the appended tail. Use exact pairs of examples in review so a reader can check the interpretation without relying on a mnemonic. Match simple prefix and directory alias slashes carefully, and consult the alias documentation for forms that use regular expression captures.

Test both the directory route and a direct static file. When a request path ends in a slash, Nginx can use an index directive to try named default files. In an ordinary directory with an existing index.html, requesting the root slash can serve that homepage. An internally selected filename can be processed by another location. If a folder has no permitted index and listing is disabled, the directory request can return a forbidden response even when a named file below it is readable. Checking only the homepage misses mistakes in images and downloads. Checking only a direct asset misses errors caused by directory indexing or internal routing.

The try_files directive likewise influences how a missing path is handled. Its candidates are checked in sequence using the current root or alias mapping. A final explicit 404 is helpful for a static site because missing files remain recognizable. If the last argument names an internal URI, the resulting path may map to another location. For example, sending every request to an application shell might leave a missing PDF returning HTML with a success status. The release switch would look green until a customer tries to open the file. For static assets validate a representative content type and marker, and verify the expected status for at least one intentionally missing destination.

Worksheet for paths before and after the example release switch
RequestSpring lookup or resultSummer lookup or result
mauli.test /spring/index.htmlsummer/index.html
mauli.test /downloads/price-list.txtspring/downloads/price-list.txtsummer/downloads/price-list.txt
mauli.test /forms/signup.txtshared/signup.txt via the independent aliasshared/signup.txt, unchanged
mauli.test /downloads/never.txt404 from the site rule404 from the site rule
library.test /library/index.htmllibrary/index.html

In the worksheet, the forms reference denotes a URI, and its independent file lives at shared/signup.txt in the lab. Append the entire URI only in the rows governed by root. For the alias row, strip the matched prefix according to its mapping. For a proxy rule that hands off a request to a program, the filesystem worksheet would need a handoff step instead. The application can decide what to serve using its own bundle or configuration. A document root is one action for one kind of route, not a promise about every URI exposed by the listener.

Use the selected hostname as a control when testing. With several sites on one listener, an IP-only request may select a fallback site. Removing its default role to make your own URL work can change unrelated sites. The targeted hostname probe avoids that uncertainty. It selects the correct virtual site without changing DNS for other users. First compare its current marker to your expectations. A future before-and-after record is only as good as the baseline it started with.

Prepare both releases and a recoverable configuration

Keep the original release intact and build the new release next to it. A release directory should have the files the web server will make public and the necessary directory hierarchy. Consider the URLs already used by people or shared by other sites. Preserve a small set of action-critical URLs in your test plan, including the homepage, one public download, any path supplied by another service and a deliberate missing path. If public paths legitimately move at the same time, document redirects and verify their destination, status and inputs as a separate change. This task focuses on keeping those paths stable across two releases.

A directory can be readable to the editing account while its contents are inaccessible to the process serving the site. The worker needs appropriate traversal on each parent directory and read permission on the file. On Linux directory traversal is associated with the execute bit on that directory. To open a known file under nested folders, each parent has to permit traversal for the worker identity, subject to other policy. Directory listing needs separate permission and is also controlled by server configuration. Reading the file as the login user proves very little when the worker uses another account or group with different policy.

Find the worker identity through your approved service inspection, and inspect the exact failing path component. A root-owned file of public course material may be readable by a group that includes the service account. Keeping site files under a dedicated directory allows access to be concentrated there. There is no need to open your own login home, SSH directory, application secrets or unrelated project releases to the service. A recursive permission change to the parent is disproportionate and can introduce new security problems. Use only the access the process actually needs and check that your deployment account still controls edits. A file can be readable without being writable by the web server.

On a Linux system where SELinux is enforcing, the mandatory policy can also govern access even when ordinary ownership and permission bits look correct. Think of the mode bits as one check on a file request and the policy label as a second check based on what the process may access. The label needs to match the distribution's policy and the role of the path. A new custom directory may need a persistent context assignment. Look at the existing labels and audit messages first. On a system without enforcing SELinux, a permission error has another source. These are host-specific checks. A local loopback exercise running as the editing user verifies mapping and activation, but cannot prove the production worker identity or a permitted SELinux label.

Before editing the real config, record the exact active source file and any symlink needed to reach it. Save a protected backup outside all configuration includes and compare it with the current file. Keep the previous content directory accessible and leave its expected marker in your verification record. A successful restore needs both earlier instructions and the files they reference. If a deployment uses a current link to publish release directories, restoring the link is an additional option where the documented workflow supports it. Understand the link update, caching and open files before substituting a different deployment model. In this lab the only released instruction that changes is one root line.

For a real release, also establish who can change the target directory while you test. A server worker that has write access to its own public content can complicate release integrity. In the simple static case the worker can usually work with only read and traverse access, while a deployment identity manages the directories. If an application accepts uploads, keep its writable paths purpose-built, separate from executable code and unrelated releases. Do not assume those upload paths move with the public content root. Inventory open dependencies, the operations owner and what should happen if the new release cannot answer. On a single authorized practice site those facts are easy to observe, which makes it a good starting point before testing a shared deployment.

Make expected observations explicit beforehand. Before activation you should see spring on the workshop and the original library marker on the other site. After activation workshop should serve summer on the homepage and in the download. The unchanged alias and library should retain their markers. The deliberately missing file should still return the intended 404. After restoring the saved file, workshop should again serve the spring markers. A syntax success after restore and a passing response from neither site would be a failed recovery. The acceptance conditions name all the signals you need to decide whether the job is done.

Switch the selected root, verify the response and restore it

The hands-on task uses one unprivileged Nginx process and two named sites on loopback. It changes a single repository-style release setting in a temporary directory, reads response evidence, and then rolls back. You need Bash, Nginx with its ordinary HTTP modules, curl and Python 3. Use a disposable Bash shell as a regular account on your practice machine. Follow the blocks in order in that same shell, and stop at a reported error. The process listens only on 127.0.0.1 on the high port 18883. Choose an unused high port and replace all corresponding references if the example port is taken. The lab requires no public DNS entries, public listeners or root access.

Start by creating the releases, shared content and the independent library. Distinct tiny files stand in for a full website. A simple body gives you proof that the expected bytes arrived even when two releases use the same layout and status. Keep all three types of content. The ordinary release asset will change with the root, the aliased form should remain independent, and the library control should detect a change that escaped the intended virtual site. The cleanup trap stays attached to your disposable shell so exiting can stop the child and remove its files.

if [ "$(id -u)" -eq 0 ]; then
  printf 'Run this lab as an ordinary user.\n' >&2
  exit 1
fi
nginx_bin=$(command -v nginx) || exit 1
web_lab=$(mktemp -d /tmp/rb-nginx-roots.XXXXXX) || exit 1
lab_pid=
root_lab_cleanup() {
  if [ -n "$lab_pid" ] && kill -0 "$lab_pid" 2>/dev/null; then
    kill -QUIT "$lab_pid"
    wait "$lab_pid" 2>/dev/null || :
  fi
  case "$web_lab" in
    /tmp/rb-nginx-roots.??????) rm -r -- "$web_lab" ;;
  esac
}
trap root_lab_cleanup EXIT
mkdir -p "$web_lab/spring/downloads" "$web_lab/summer/downloads" \
         "$web_lab/shared" "$web_lab/library" "$web_lab/sites" "$web_lab/backups"
printf 'mauli-spring-home\n' > "$web_lab/spring/index.html"
printf 'mauli-summer-home\n' > "$web_lab/summer/index.html"
printf 'mauli-spring-prices\n' > "$web_lab/spring/downloads/price-list.txt"
printf 'mauli-summer-prices\n' > "$web_lab/summer/downloads/price-list.txt"
printf 'mauli-shared-form\n' > "$web_lab/shared/signup.txt"
printf 'unchanged-library\n' > "$web_lab/library/index.html"

Now put the shared server setup in the entry file and the two ordinary sites in separate files. The quoted document delimiters preserve Nginx's configuration variables. Nginx receives an explicit prefix and entry path, so its logs and runtime directories belong to this experiment. The entry file and its include are in the same temporary root for a clear path trace. The fallback server in the entry file adds an independent unknown-host check. The Mauli location for forms uses alias, while most other requests use the site's root. The library site has its own explicit root.

cat > "$web_lab/nginx.conf" <<'NGINX'
worker_processes 1;
pid nginx.pid;
error_log error.log notice;
events { worker_connections 32; }
http {
    default_type text/plain;
    client_body_temp_path body;
    proxy_temp_path proxy;
    fastcgi_temp_path fastcgi;
    uwsgi_temp_path uwsgi;
    scgi_temp_path scgi;
    log_format release '$server_name "$request_uri" "$request_filename" $status';
    access_log access.log release;
    server {
        listen 127.0.0.1:18883 default_server;
        server_name fallback.test;
        return 404 "unknown-site\n";
    }
    include sites/*.conf;
}
NGINX
cat > "$web_lab/sites/mauli.conf" <<'NGINX'
server {
    listen 127.0.0.1:18883;
    server_name mauli.test;
    root spring;
    index index.html;
    location / {
        try_files $uri $uri/ =404;
    }
    location /forms/ {
        alias shared/;
    }
}
NGINX
cat > "$web_lab/sites/library.conf" <<'NGINX'
server {
    listen 127.0.0.1:18883;
    server_name library.test;
    root library;
    index index.html;
    location / {
        try_files $uri $uri/ =404;
    }
}
NGINX
cfg() {
  "$nginx_bin" -e stderr -p "$web_lab/" -c "$web_lab/nginx.conf" "$@"
}
cfg -t || exit 1
cfg -T > "$web_lab/parsed-before.txt" || exit 1
grep -E '^# configuration file|server_name|[[:space:]]root |[[:space:]]alias ' \
  "$web_lab/parsed-before.txt"

The function uses the same executable, prefix and config for both parser invocations. Lowercase test checks the candidate. Uppercase test also prints the configuration files read. The private dump contains file boundaries. The grep selects those boundaries and a handful of directives, so you can tie a root to the Mauli site and distinguish it from the library declaration. The expected output lists the two included files, the spring root, the alias, and the independent library root. A raw grep over every file in the directory would also match a backup after you create one. This grep works on the parser's view instead.

Start the private listener using the same prefix and file. Launch the executable directly for the background process, allowing the shell to identify the actual child rather than a function wrapper. The guard prevents any pre-existing listener from being mistaken for the new Nginx process. It compares the new PID file with the child's actual identifier. Failure here points first to starting conditions such as a bind error, not to the meaning of a request path. Leave any existing listener alone and use a different unused high port for the exercise if needed.

"$nginx_bin" -e stderr -p "$web_lab/" -c "$web_lab/nginx.conf" -g 'daemon off;' &
lab_pid=$!
for attempt in 1 2 3 4 5 6 7 8 9 10; do
  if [ -s "$web_lab/nginx.pid" ]; then
    break
  fi
  if ! kill -0 "$lab_pid" 2>/dev/null; then
    break
  fi
  sleep 0.2
done
if ! kill -0 "$lab_pid" 2>/dev/null ||
   [ ! -s "$web_lab/nginx.pid" ] ||
   [ "$(tr -d '[:space:]' < "$web_lab/nginx.pid")" != "$lab_pid" ]; then
  printf 'The isolated listener did not start. Check its private log and port.\n' >&2
  if [ -r "$web_lab/error.log" ]; then tail -n 10 "$web_lab/error.log" >&2; fi
  exit 1
fi

Make the comparisons repeatable. The next function uses plain HTTP and supplies the intended name while connecting to loopback. It saves one response at a time to the temporary folder and prints status and a short body. Inspect both. A 404 for the intentional missing path serves as a negative control. The unknown-host response uses a different content marker, so those two 404 responses tell different stories. There is no need to check the ordinary welcome page in this lab. Its fallback intentionally declines unrecognized names.

probe() {
  local name=$1 path=$2 status
  status=$(curl --noproxy '*' --max-time 5 -sS \
    --resolve "$name:18883:127.0.0.1" -o "$web_lab/response" -w '%{http_code}' \
    "http://$name:18883$path") || return
  printf '%s %s HTTP %s\n' "$name" "$path" "$status"
  head -c 120 "$web_lab/response"
  printf '\n'
}
probe mauli.test /
probe mauli.test /downloads/price-list.txt
probe mauli.test /forms/signup.txt
probe library.test /
probe mauli.test /downloads/never.txt
probe unknown.test /

Record spring home, spring prices, shared form and the unchanged library. They should all arrive with HTTP 200. Compare them to the last two 404 responses. You should see the unknown-site marker only for the unknown hostname. Those baseline observations describe a running service, while the earlier parse describes instructions available on disk. You need both because they can diverge when a configuration is edited and left unapplied. Confirm the views agree before changing the selected root.

Save the active site file outside the include selection and compare it. The short Python program limits the change to the exact spring line in the one lab site file. It requires exactly one match because zero matches would mean the old release has drifted, while multiple matches would make the intended edit ambiguous. Inspect the diff, then run the parser again before signaling the lab master. Do not use the system service controller for this private process. Continue only if the exit statuses and shown diff agree with the one-line change you intend.

cp -p -- "$web_lab/sites/mauli.conf" "$web_lab/backups/mauli.conf" || exit 1
cmp "$web_lab/sites/mauli.conf" "$web_lab/backups/mauli.conf" || exit 1
python3 - "$web_lab/sites/mauli.conf" <<'PY'
from pathlib import Path
import sys

path = Path(sys.argv[1])
content = path.read_text()
old_line = "    root spring;\n"
new_line = "    root summer;\n"
if content.count(old_line) != 1:
    raise SystemExit("Expected exactly one spring root in the Mauli site file")
path.write_text(content.replace(old_line, new_line))
PY
test "$?" -eq 0 || exit 1
if diff -u "$web_lab/backups/mauli.conf" "$web_lab/sites/mauli.conf"; then
  printf 'No root change detected.\n' >&2
  exit 1
else
  diff_status=$?
  test "$diff_status" -eq 1 || exit 1
fi
cfg -t || exit 1
kill -HUP "$lab_pid" || exit 1

The diff prints the old and new root. For diff an exit status of one indicates a difference, which is expected here. The earlier cmp compared the saved copy before the edit. The diff check rejects an unchanged candidate or an inability to read the files. Read the visible diff for the precise scope. The HUP signal asks the private master to apply the candidate. It may need a short moment to bring up replacement workers, and it retains the prior configuration when a reload cannot be applied. Probe the active response instead of treating a successfully sent signal as deployment proof.

probe mauli.test /
probe mauli.test /downloads/price-list.txt
probe mauli.test /forms/signup.txt
probe library.test /
probe mauli.test /downloads/never.txt
probe unknown.test /
tail -n 6 "$web_lab/access.log"

After the reload settles, the two release markers should say summer. The forms marker and the library marker should agree with the original results, and the missing path should still be missing. The file mapping log displays the computed filename at the end of request processing. In this lab the successful download line should name the summer file. Use it as corroboration, because it may still show a computed candidate for a missing or synthetic response. Pair the log with actual bytes and statuses before claiming which file was served.

Restore the saved input and use the same checks again. This time compare it byte-for-byte with the saved version before parsing and signaling. The spring contents were never edited or deleted, so the restored rule still has a valid target. Give the restarted workers a moment and repeat the probes if an early request sees the prior generation. Save your results before removing the lab files. The final test checks teardown, while the earlier recorded bodies demonstrate successful rollback.

cp -p -- "$web_lab/backups/mauli.conf" "$web_lab/sites/mauli.conf" || exit 1
cmp "$web_lab/backups/mauli.conf" "$web_lab/sites/mauli.conf" || exit 1
cfg -t || exit 1
kill -HUP "$lab_pid" || exit 1
probe mauli.test /
probe mauli.test /downloads/price-list.txt
probe mauli.test /forms/signup.txt
probe library.test /
root_lab_cleanup
trap - EXIT
test ! -e "$web_lab" && printf 'Nginx root lab removed.\n'

Compare a valid configuration with an incomplete release

Once you have completed the first full run, repeat the task with a deliberately incomplete summer release. Use a fresh disposable directory so the failed test cannot be confused with the previous success. Follow the blocks through the spring baseline. The new experiment removes one synthetic download from the public-facing summer directory before switching the root. The file stays available in a private holding directory inside the lab for easy recovery. This reproduces the type of mistake that can happen when a build step publishes a homepage but omits a referenced file.

mv "$web_lab/summer/downloads/price-list.txt" "$web_lab/backups/summer-prices.txt" || exit 1
test -f "$web_lab/summer/index.html" || exit 1
test ! -e "$web_lab/summer/downloads/price-list.txt" || exit 1
cfg -t || exit 1

The successful config test at this point is expected. It still parses the spring root and tests applicable configuration references. The summer content has its own readiness question. Next run the intended switch block, wait for activation and repeat the after-check. This time the chosen root and the homepage should still say summer. The price list should return 404, and the library, form and deliberate negative case should give the same results as before. The candidate syntax test had no instruction that said the price list was a required release artifact. A configuration parser and a contents acceptance test cover different requirements.

Use your written rollback signal. If access to the price list is required for a usable release, treat the after-check as failed even though the homepage is correct. Restore the exact saved configuration and confirm the expected spring homepage and price list before cleaning up. If time allows before your cleanup block, restore the summer file too and compare its bytes to the expected simple marker. Keep your observations in order so the person reviewing the exercise can distinguish recovery of the active site from repair of an inactive release. A real pipeline would typically validate required release files and URLs before asking for promotion.

mv "$web_lab/backups/summer-prices.txt" "$web_lab/summer/downloads/price-list.txt" || exit 1
grep -Fx 'mauli-summer-prices' "$web_lab/summer/downloads/price-list.txt" || exit 1

In a second thought experiment, a release inserts an unrelated text file with a name that the server uses as an index somewhere else. That can leave syntax and many URLs unaffected while changing a single directory response. Choose the most valuable directories and explicit links before the exercise because exhaustive checking is rarely possible on a real site. For the dairy, high priority goes to the content that visitors need for an actual decision: the homepage, the product list, and perhaps a working way to reach the owner. An unchanged independent route belongs in this check because an update can affect another site's customers through shared configuration.

Write this failure as a three-stage explanation. The first stage passed the parse of the candidate root declaration. The second selected summer and yielded its homepage while failing the required asset request. The last recovered the known spring responses using a retained directory and a verified configuration backup. Each sentence should say what evidence supports it. That habit guards against assuming every valid configuration produces a valid website, or that a successful rollback necessarily repaired the files that made the new release incomplete.

Diagnose the homepage, download and independent routes

Consider an after-change check where the homepage says summer and the price list returns 404. You have already established that the new release was selected for a request to the homepage. Keep the exact same origin address and hostname as you test the direct download. Find the download's final URI and computed filename in the appropriate log. Confirm that the summer directory has the expected nested folder and file. If a more specific location overrides root, work through that mapping instead of searching the summer folder blindly. Compare the configuration used in the successful homepage test before touching the service again. Missing one asset is evidence for a specific route problem, not evidence that the reload failed entirely.

If the homepage shows spring while the direct curl probe on the instance shows summer, check whether the browser used the same hostname and path. A user may still be receiving content from a separate public delivery layer or a local browser cache. Compare response headers, each request's destination, and the availability of an origin log entry for that request. If the public route lands on several instances, confirm the deployment state on the specific backend that served it. An instance-local loopback result proves the rule on that machine only. A deployment through a pool of origins needs a full pool verification plan. Changing the root on every instance simultaneously would make it harder to isolate either a bad release or a routing mismatch.

Now imagine the correct hostname returns 403 on forwarding into the summer directory. Start by distinguishing a whole-tree denial from a failed directory index. Probe a specified file such as the working download path, then probe the homepage and another expected file. A named file can work when no permitted index is available at the root slash. If both named files are forbidden and the error message names permission denied, the issue may be with a common ancestor, a file permission or a policy label. The diagnostic should show precisely which object the worker tried to use. Locate the first denied component without opening personal directories or modifying unrelated sites.

On Linux a command such as the following can help inspect the ordinary ownership and mode bits of the directories leading to one path. Adapt the example to the actual computed filename, and run the label branch only where your distribution offers it.

# Read-only examples for an authorized Linux training server.
namei -l /srv/mauli/summer/downloads/price-list.txt
ls -ld /srv/mauli/summer /srv/mauli/summer/downloads
ls -l /srv/mauli/summer/downloads/price-list.txt
if command -v getenforce >/dev/null 2>&1; then
  getenforce
  ls -Zd /srv/mauli/summer /srv/mauli/summer/downloads/price-list.txt
fi

Read across the ownership and mode columns rather than simply counting how many entries are listed. Compare them to the service account and group identified in startup inspection. On an enforcing system, even a world-readable demonstration file can be unavailable due to policy. Examine the service's errors and the local audit information through the normal authorized workflow. If the new directory should use the same contexts as a known working public directory, use the host policy's persistent mapping procedure and verify the resulting labels. A guessed context or a permissions change to all releases makes the incident harder to reason about. A move of existing files can retain labels that differ from a new file created under the destination, which is another reason to observe rather than assume.

If the library marker changes alongside the site, treat the control failure as real even if your homepage looks perfect. Inspect whether the root was changed at a broader context level, whether both sites share a path, or whether the probes accidentally used the same hostname. Separate site files do not automatically create different values for every setting. A shared root inherited by two definitions can intentionally mean the same folder. The exercise gives both sites explicit roots to make the desired isolation clear. The fallback marker is a separate check on host selection. When an unexpected fallback appears, go back to the hostname and listener before analyzing file modes.

Use a specific observation to select a document-root check
ObservationFirst difference to investigateEvidence of recovery
Syntax fails after the edit.Match the invocation and review the exact changed declaration and its context.A successful test of the intended candidate before activation.
Direct probe still says spring.Check the log for reload acceptance and confirm the matched hostname and active rule.The expected summer marker from a controlled new request.
Homepage works but the download is absent.Compute the actual file path and verify the release contains it.The intended download's contents and the requested response status.
Folder entry is forbidden but a named file works.Check the index list, available files and any rematched location.The correct homepage body from the same slash path.
Both sites suddenly show the new homepage.Compare authority and inherited root or fallback behavior.New site marker and independently preserved library marker.

A safe restore keeps recovery evidence distinct from cleanup. Compare the copied config with the saved version, test it, then request the same site and asset paths. If the previous release files have been removed, restoring the old filename is not a complete recovery. The previous release needs to exist and remain readable. If the old frontend depends on an application version or data transformation, record that dependency before promoting the new release. This file-only example deliberately avoids that dependency so you can see how configuration plus retained content supports a reliable rollback.

Write a release record and test the useful differences

Prepare a short report another trainee could reproduce. Include the old and new root values, the site file you changed, the include that made it active, the actual listener and hostname, and the saved copy's location. Attach the before, after and restored results for the homepage and download. Record the expected status for the intentional missing file. Report both the unchanged alias and the unrelated library. Keep the report focused on the release markers and paths, with any internal names changed when those details should remain private.

For a second task, choose one change that should not affect a neighbor. For example, add a file named contact.txt only under summer, then predict the before, after and restored results. In the before and restored states it should be missing. In the summer state it should be served by the ordinary prefix from the summer directory. Throughout all three states the alias and library remain stable. This is a valuable feature test because it proves the lookup moved rather than merely comparing two copies of the same homepage.

For a third task, read the filesystem mapping from the three successful requests. Using the parsed config and logs, write the exact final URI for the homepage, the computed path for the price list and the alias target for the form. Then explain which part of each path comes from the request and which comes from a directive. Test the form path with a different filename to check the mapping without accidentally selecting the direct root. The answer should make clear why a single root line controls some requests while another directive controls the form.

A more advanced comparison can place a new private release under a published current link. Draw the pre-change link target and the expected target afterward. Explain how you would detect a mismatch between the configured root, the resolved target and what a request got. If you are operating a team deployment, use its prescribed atomic publication mechanism and rollback method. For this chapter, the shown lab edits one line and applies it, which keeps the file mapping lesson visible and independently testable.

Interview questions, short quiz and revision cards

Can a document-root release use the existing public address?

Yes. If the listener and virtual site stay fixed, requests can keep using the same scheme, hostname, port and URL paths. The selected root changes how the server locates static files. Test the old shared URLs against the new release before accepting that they still work.

Why did the form stay the same when the main document root changed?

Its prefix selects a location with an alias that maps the form URL to an independent directory. The default root was changed for ordinary release files. Comparing the computed filename and response body verifies that the form remained under the intended mapping.

What should you save before editing a site's root?

Keep the exact active configuration or managed source and record any enablement link used to reach it. Keep the previous release content available and record its expected response. Store the copy outside included directories. Both the original rule and the original content are needed for this rollback.

Why can a filesystem permission check as the login user mislead you?

The worker can use a different account, group and security context. It needs traversal on parents and permission to read the file, plus any policy access required by the host. Verify the path named by the server and diagnose the specific denial before changing permissions.

Does an HTTP 200 response prove the new document root is active?

It proves a service returned a successful response. Check the intended hostname and path, the expected new marker, a uniquely changed download and an independent site marker. The old release, a cache or another virtual site might return its own successful status.

Quick quiz

  1. A location declares root /srv/summer; and handles /assets/manual.txt. Which path is ordinarily calculated?

    1. The root directory followed by the full assets path
    2. The root directory followed only by the filename
    3. The folder containing the configuration file followed by the filename
    Check the first answer

    A. The full URI path is appended, giving the assets directory under the named root. A simple prefix alias would have different replacement behavior.

  2. Which observation is a valid rollback result for this lab?

    1. The saved file was copied, with no response checked
    2. Spring homepage and prices return, and the shared form and library markers remain
    3. The bare address comes back with a fallback error
    Check the second answer

    B. The old release returns through the same paths and the independent controls still work. Pair that with a successful syntax check and the deliberately missing path's expected result.

  3. A browser sees spring and a correctly named local probe sees summer. What is a reasonable next comparison?

    1. Change ownership of both releases before looking at the requests
    2. Remove other virtual sites
    3. Compare the actual destinations, cache evidence and origin logs for the two requests
    Check the third answer

    C. The local config and release mapping succeeded for one request. Determine which route or cache supplied the different public response before making a new server change.

Full request path

Root appends the request path. A simple location alias replaces the matched prefix using its configured directory.

Two content markers

Use distinct release markers on the homepage and a direct asset. Compare an unchanged alias and a separate site.

Worker access

Check traversal, file read permission and host policy on the precise path. Keep public files in a dedicated tree.

Recover the rule and content

Retain the prior release, save the chosen configuration outside includes, then test the restored HTTP path.

Primary references