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

Chapter 8: Configuring Nginx and Apache

AWS Cloud

8.1 Where the configuration lives

Friends, before changing a config you must know where the file is. The table shows common package defaults for the main file, site files, site activation and logs. Verify the paths, account and include rules used by the service on your machine.

Item Nginx (AL2023 / CentOS) Nginx (Ubuntu) Apache (AL2023 / CentOS) Apache (Ubuntu)
Main file /​etc/​nginx/​nginx.​conf /​etc/​nginx/​nginx.​conf /​etc/​httpd/​conf/​httpd.​conf /​etc/​apache2/​apache2.​conf
Your site files /​etc/​nginx/​conf.​d/*.​conf /​etc/​nginx/​sites-​available/ /​etc/​httpd/​conf.​d/*.​conf /​etc/​apache2/​sites-​available/*.​conf
How a site is enabled Read when the active configuration includes conf.d/*.conf Symlink into sites-enabled/ if selected by the main include Read when the active configuration includes conf.d/*.conf sudo a2ensite name.​conf
Default site server block inside nginx.conf sites-​enabled/​default welcome.conf + /var/www/html 000-default.conf
Default web root /​usr/​share/​nginx/​html /var/www/html /var/www/html /var/www/html
Ports file inside each server inside each server Listen in httpd.conf /​etc/​apache2/​ports.​conf
Worker user nginx www-data apache www-data
Logs /var/log/nginx/ /var/log/nginx/ /var/log/httpd/ /​var/​log/​apache2/
Test config sudo nginx -t sudo nginx -t sudo apachectl configtest sudo apache2ctl configtest
Show loaded sites sudo nginx -T sudo nginx -T sudo httpd -S sudo apache2ctl -​S

Ravindra Bagale's Tip

Keep a site-specific change in its own included site file when your installation supports that layout. The main file owns shared settings and the include chain. To disable a site, use the relevant package workflow or keep its file outside the include selection, then validate and apply the new configuration. Keep your managed site files under backup or version control.

Always back up before editing

Save a verified copy of the active site file in a protected backup directory outside every active include pattern. Record any enabled link and its target. A file ending in .bak stays outside *.conf but can still match a broader rule.

Ravindra Bagale's Tip

A backup like mysite-old.conf inside an included conf.d/*.conf pattern can cause a duplicate declaration and a conflicting server name warning. Save the backup outside active include directories.

Lab

On your practice server, match the binary and entry options in the running service before inspecting its parsed configuration. Locate the included site file, listener and hostname together. Save a protected copy outside the include selection if you will change it. The expanded lab below lets you trace these steps with disposable files.

Start with the request that reached the server

Imagine you look after two small training sites on one EC2 instance. The library should show a reading list and the workshop should show this week's exercise. A colleague updates the file called workshop inside a configuration directory. The command that checks configuration reports success. A new browser request still shows last week's exercise. At this point you could open every text file with the right name, or you could trace which program served that request and which files that program reads. A trace gives you a way to prove that you have found the right file before making any changes.

A configuration file is a set of instructions a server reads to decide how to behave. It might say to receive connections on port 80, use a different document directory for each hostname, record errors in a particular log, or send certain requests to a separate application. A directive is one instruction in that file. A web page such as an HTML file is content the server may send to a browser. The configuration selects how to locate that content. It can also choose to generate a response or hand the work to another program. The distinction tells you what to inspect if a page is wrong. Editing a page changes the bytes available to be served. Editing a configuration rule may change which page is chosen.

The entry file is the main file the server is told to read. It can bring in other files through an include directive, much as a class timetable can refer a student to another sheet for room assignments. The additional file still participates in the instructions for the same server. A file count in a directory would confuse available files, enabled files, and backup copies. A useful map follows each applicable include from the entry file to the instructions for the particular host, path, and port.

Make your first observation specific. Record the URL you tested, which machine you tested from, the exact result, and the time. Compare a browser request to the intended workshop hostname with a request sent directly to the intended instance while preserving that hostname. If you change the IP address and the hostname at once, you have changed two inputs and cannot tell which change selected a different site. On an internal lab you can force the connection to loopback, the address that points back to the machine running the test, and still supply the workshop name in the request. For HTTPS the name is needed during the encrypted connection setup as well, so a plain HTTP header override alone is insufficient for the HTTPS equivalent.

curl --noproxy '*' --max-time 5 -i --resolve workshop.test:18881:127.0.0.1 http://workshop.test:18881/marker.txt

This request makes sense only while an HTTP service is actually accepting connections on the example address and port. The resolve option tells curl where to connect for this one hostname and port, without editing DNS settings or the system hosts file. The URL preserves the hostname the site uses for selection. The no-proxy argument excludes a configured proxy from this local exercise. The timeout bounds the wait. The combined output shows response headers and body, so you can confirm both the response status and the intended file contents. A successful connection gives evidence about that one route. It says nothing by itself about a load balancer, a browser cache, the public address or any other machine.

Now list the evidence you need in order. First identify the listener, which is the address and port a running program uses to accept connections. Find the program and the service or container that launched it. Read that service's startup options to identify the entry file. Ask the same program to parse that entry file and trace its includes. Finally find the matching site rule and log for the test request. Keep a copy of this small map before editing. It is easier to explain why a change should fix the workshop when you can name the exact link in the chain that is wrong.

Connect an address to a running service and entry file

On a typical systemd Linux machine, a unit describes a managed component. A service unit records how its program should start. The unit name, package name and executable name sometimes differ. Apache typically uses a name such as apache2 on Ubuntu or httpd on Amazon Linux. An instance can run an Nginx service and an Apache service at the same time if their listeners are arranged to avoid a conflict. A front web server can also receive the public request while a second server receives a private forwarded request. A program installed on disk is merely a candidate until you identify the listener handling your request.

# Read-only on the Linux machine where you believe the listener runs.
ss -ltnp
systemctl status nginx.service --no-pager
systemctl cat nginx.service
systemctl show nginx.service -p MainPID -p ExecStart -p FragmentPath -p DropInPaths

The socket command lists listening TCP sockets with numeric addresses and ports and asks for process details when the current user can see them. In particular, permission limits can omit process names or identifiers. Observe the local address as well as the port. A row at the IPv4 loopback address means the listener is available locally on that address. A listener bound to all IPv4 interfaces is available across those interfaces subject to routing, firewall and other controls. There are separate IPv6 addresses and bindings. IPv4 behavior cannot be inferred from an IPv6 row without checking the actual system settings and connection. Use the Apache unit name you have already identified when tracing Apache.

The status command tells you whether the unit is active and may show the parent process and recent messages. The cat command shows the source unit and its drop-ins, which are additional unit files used to override settings. The show command prints selected unit properties in compact form. A fragment path here belongs to the service manager's configuration. It may be a file ending in service. The web server entry file is a different document. Look at the executable and its arguments in the start command. A drop-in can replace the start command, so a path in the vendor's original unit file may differ from the arguments in use. Also distinguish the unit definition available now from the command that created a process already running. A definition may have been changed since startup.

Consider a listener at 127.0.0.1:8088 with parent process 4512. The service manager reports that process as its main process. A local startup command contains /usr/sbin/nginx -p /srv/training-nginx/ -c conf/nginx.conf. The prefix option tells Nginx to use the named directory as its path prefix. The configuration argument selects an alternate entry file. In this example the relative configuration path should be read against that prefix, giving /srv/training-nginx/conf/nginx.conf. A bare Nginx command launched from a shell could instead read the package default. Both files can pass a syntax check. The positive result for the package default provides no evidence about the service that started with the alternate path.

For Apache, an explicit absolute configuration path supplied with the file option removes the ambiguity about which entry file to parse. A relative file argument is resolved against the initial server root. Apache's server root is a base for server files and is separate from the document root used to find site content. A wrapper such as apache2ctl may supply environment variables the packaged configuration expects. Compare the installed wrapper with the service definition before replacing it with a direct binary command. Preserve startup options and applicable environment when asking the parser to reproduce that service's view. For example, a configuration section conditional on an Apache define can disappear from a diagnostic parse that omits the define.

A service unit may call a shell wrapper, run inside a container or load arguments from an environment file. In a container, /etc/nginx/nginx.conf refers to a path inside its filesystem. A file with the same path on the EC2 host may be unrelated. Find the container's image, startup arguments and mounts through your normal deployment tooling. A mount makes content from one location available at another path and can replace the file originally supplied by the image. A source repository may be the intended place to change that definition because a one-off edit inside the running container can disappear on recreation. This question matters even when the local administrator has the permission to edit both places.

Read only as much process and startup detail as you need. Configuration arguments, environment and file contents can contain private internal locations or credentials. Keep diagnostics local and share a minimal summary of listener, path and error with the owner of the service. If your login cannot confirm the process or access the file, record the missing evidence and use the approved administrator workflow. File search with broader permissions would reveal more names without establishing which program read them.

Follow includes, links and defaults with the right parser

A path table is a starting point for a package layout. On an ordinary AL2023 lab you often start at the system Nginx file under /etc/nginx/ or the main Apache file under /etc/httpd/conf/. On Ubuntu Apache normally starts from its apache2.conf under /etc/apache2/. An operating system family is a label for a distribution with its own packages and conventions. The configuration belongs to the package or installation method as well as the operating system. The Ubuntu software repository, an upstream repository, a container image and a source build can place files differently even on the same operating system. Treat any table entry for default root, log directory or worker account as a candidate until the effective configuration confirms it on your host.

An include accepts a literal path or a pattern. A wildcard is a pattern character that matches any text allowed at that point. When the rule says to include files ending in dot conf in a directory, workshop.conf matches it and workshop.conf.bak does not. The rule could instead select every file in the directory. In that layout, adding the backup next to the real file can make it eligible. Some packages include actively linked site files from a directory called sites-enabled. That directory name does not grant or remove any special power. The include directive is what makes the policy work. Prefer a backup directory outside the include patterns, and verify the backup and original path before any activation.

A symbolic link is an entry that names another location. In an available and enabled layout, a maintained source file might sit in the available directory and a link in the enabled directory points to it. The parser opens the enabled name, follows it to the destination and reads the same contents. Listing the available file proves it exists. Listing the link proves there is an activation entry. Resolving the target shows whether it points to the right file. The server's parsed view establishes whether the entry is actually read. For Ubuntu Apache, the package's a2ensite command manages those links in its usual layout. Enabling a config on disk leaves any running process with its previously accepted configuration until the appropriate activation procedure succeeds.

# Typical diagnostic forms. Match the executable and startup options first.
nginx -V
sudo nginx -T

# A named alternate Nginx program configuration.
sudo /usr/sbin/nginx -p /srv/training-nginx/ -c conf/nginx.conf -T

# Use the wrapper appropriate to your Apache installation.
sudo apache2ctl -t
sudo apache2ctl -t -D DUMP_INCLUDES
sudo apache2ctl -S

Nginx's uppercase version option shows the build's configure parameters. Treat the configured default path it prints, if present, as a build fact. Its uppercase test option runs the configuration test and prints the files that parse read. Some references are opened during the check, so the account and environment can matter. Ubuntu Apache's wrapper can test configuration and show includes with the displayed define. The uppercase S option reports Apache's parsed virtual host setup. It is useful for finding host declarations and their file and line references. It does not produce a complete rendering of every active setting. A syntax result for either program describes the current files that one invocation read. It does not dump the previously accepted configuration out of workers already handling traffic.

Consider the difference between three observations about workshop. A search tool reports a hostname string in six files. The Nginx dump marks two of those files as included and one contains a live server declaration. A direct request reaches the intended listener and returns the marker expected from that declaration. The first observation gives search candidates. The second gives the parser's view and excludes unread copies. The third shows the behavior of the live process for a particular input. In the opposite order, a marker alone gives no exact filename, and an isolated grep over the filesystem tells you nothing about which result won. Use the three results for the questions they can answer.

When filtering output, keep file boundaries and account for errors. In an Nginx dump the header lines identify the configuration file for the following text. A grep that prints only root and server name tokens will remove those headers unless you explicitly include them. It might show a directive from a default site, a comment, an upstream name, an unrelated server block, or a second port without context. Pipes also need care in a shell because the final filter can succeed even when an earlier command emitted a partial result before failing. Check the parser's own status and messages first. Inspect enough surrounding lines to see which block owns a directive. A structured answer has the entry path, the include that matched, the site file, the listener and the specific name that chooses the rule.

Some configurations include files inside other includes. Under Apache, an IncludeOptional directive lets an optional pattern have no match, while a required include can make a missing file fail the configuration check. Verify whether the matching file must exist and whether the file is independent or included inside another context. A site file cannot be pasted into any arbitrary location and expected to mean the same thing. If a setting inherits a parent value, the difference between a global default and a site-specific override depends on the module and its directive. Start from the effective rule for the selected request and use that directive's documentation to work forward.

Trace a wrong workshop page without guessing at a fix

The workshop problem now has four observations. A browser at the workshop name returns the text Workshop week 3. On the intended instance, the program listening on the expected port is Nginx. A read-only dump for its startup command reports the main file and an include for enabled site entries. Two workshop files exist on disk. One lives under templates and says to serve content from /srv/workshop/week-4. One is reached from the enabled directory and still says /srv/workshop/week-3. The library file is reached through an independent link. Writing down these observations lets you separate an outdated page from a configuration selection mistake.

Picture the path as a short set of decisions. The connection first arrives at the intended network endpoint. Nginx checks the hostname on that listener and selects the workshop server definition. The workshop definition associates the request with the week 3 content. Opening the unused week 4 template in an editor establishes precisely one fact, that it exists. No amount of testing that template by itself will make the live workshop select it. If the template is an approved release source, the eventual change could be to update the controlled site file from it. If it is an obsolete work file, the right answer is to leave it out of the chain altogether. Discover the site's normal change process before using either file.

Try varying one input at a time. Hold the hostname and URL path fixed and map the connection to the intended loopback origin, if a listener accepts the test there. Then hold the connection destination and path fixed and use the library hostname. Suppose the first origin response contains Workshop week 3 and the second shows Library reading list. You now have a stable baseline for two names. If both returned the library marker, you would check whether the workshop declaration is included and whether the hostname and port are correct. For a public browser that differs from the controlled origin response, add the public edge as another stop in the chain. An HTTP cache or reverse proxy can serve a response before the origin sees the request. The origin's access log for the exact time and path can provide corroboration.

A configuration entry for the workshop and a separate library entry reduce the number of files to inspect, but separation on disk is no proof of isolation in operation. Both sites can share a main configuration, socket, TLS certificate settings, global limits or log. A rule in a global block can affect both sites even when its filename mentions one. Look at the directive's enclosing context before assigning ownership. Check the independent library marker across any authorized workshop activation. That small control detects cases where the intended page looks fixed because the fallback site or both sites changed together.

Use the correct artifact as the backup. If the active path is a link, decide whether you need to restore the link, its target content or both. Record the existing target and where the copy resides. A backup of the wrong unused workshop copy gives no recovery path for the site in service. Restrict the copy to those who should see the original and store it outside the include patterns. Separately track a content deployment or application dependency when the rollback depends on it. If the week 3 directory is removed, restoring the old path alone cannot produce a workshop week 3 response. Recovery requires the earlier files to remain available.

Make a note of the expected controller for the service. An operator using a systemd package, a container pipeline or a managed distribution may apply the same text through distinct procedures. If the repository owns the configuration, the version in that repository and the revision deployed to the host are part of the evidence. Document the actual active path alongside the repository path. The person reviewing the change can then look at both before deciding whether a direct file change would survive the next deployment.

Lab to trace an enabled link through the parser

In this exercise you create an Apache configuration under one temporary directory. The normal service stays outside the exercise. You will observe an available workshop file, enable it with a symbolic link, and compare two parser reports. In the last step, if the chosen loopback port is free, you send a request to the isolated process and confirm the workshop marker. There is no reason to edit a system configuration or open an inbound cloud port. Run this as a regular user on a practice machine that already has Apache HTTP Server 2.4, Bash, and curl. The parser walk also works without starting the optional listener. The exact local lab was checked on Apache 2.4.67. The installed module location and diagnostic wording can vary by operating system and package.

Open a disposable Bash shell and keep it open while working through the lab. Keep the names and order for this one session so that the cleanup operates on the same temporary directory and child process. The first block finds the executable, locates the package module directory and prepares the directories. On the common package layouts shown below the modules exist in one of these locations. A custom build may store them elsewhere or require another module. Stop at an error and inspect the package layout if the path cannot be confirmed.

if [ "$(id -u)" -eq 0 ]; then
  printf 'Use an unprivileged practice shell.\n' >&2
  exit 1
fi
apache_server=$(command -v apache2 || command -v httpd) || exit 1
cfg_lab=$(mktemp -d /tmp/rb-config-discovery.XXXXXX) || exit 1
lab_pid=
lab_cleanup() {
  if [ -n "$lab_pid" ] && kill -0 "$lab_pid" 2>/dev/null; then
    kill "$lab_pid"
    wait "$lab_pid" 2>/dev/null || :
  fi
  case "$cfg_lab" in
    /tmp/rb-config-discovery.??????) rm -r -- "$cfg_lab" ;;
  esac
}
trap lab_cleanup EXIT
mkdir "$cfg_lab/available" "$cfg_lab/enabled" "$cfg_lab/backup" \
      "$cfg_lab/main" "$cfg_lab/workshop" "$cfg_lab/logs"
modules=
for candidate in /usr/lib/apache2/modules /usr/lib64/httpd/modules /usr/lib/httpd/modules /usr/libexec/apache2; do
  if [ -r "$candidate/mod_mpm_event.so" ] && [ -r "$candidate/mod_authz_core.so" ]; then
    modules=$candidate
    break
  fi
done
if [ -z "$modules" ]; then
  printf 'Find the Apache module directory for this package before continuing.\n' >&2
  exit 1
fi
printf 'default-origin\n' > "$cfg_lab/main/marker.txt"
printf 'workshop-origin\n' > "$cfg_lab/workshop/marker.txt"
printf 'Apache %s; lab %s\n' "$apache_server" "$cfg_lab"

The temporary directory selector generates a fresh folder name. That gives you a clear boundary for the experiment and prevents a path from a previous run being reused accidentally. The exit trap registers a cleanup routine for this shell. The routine stops only the child you started and removes only the generated lab directory. Its narrow path check means an unset variable cannot be passed on as an arbitrary deletion path. The two marker files use different text, so they distinguish two responses that may otherwise look identical. The marker rather than your browser address tells you which file the server actually served.

Now write two configuration files. The main file binds only to the IPv4 loopback address when started. A client on the same machine can reach that address. The test parser initially reads no enabled site files. The optional include pattern tolerates that initial state. The wildcard narrows eligible files to names ending in dot conf. The declared worker account and group match your current unprivileged shell, and runtime files stay in the generated directory. The separate directory settings let the process read the two synthetic content locations during the optional request. Never substitute a home directory with personal files for those two disposable content directories.

static_modules=$("$apache_server" -l) || exit 1
{
  printf 'ServerRoot "%s"\n' "$cfg_lab"
  if ! printf '%s\n' "$static_modules" | grep -Eq '(^|[[:space:]])(event|worker|prefork|mpm_event|mpm_worker|mpm_prefork)\.c$'; then
    printf 'LoadModule mpm_event_module "%s/mod_mpm_event.so"\n' "$modules"
  fi
  if ! printf '%s\n' "$static_modules" | grep -Eq '(^|[[:space:]])mod_authz_core\.c$'; then
    printf 'LoadModule authz_core_module "%s/mod_authz_core.so"\n' "$modules"
  fi
  if ! printf '%s\n' "$static_modules" | grep -Eq '(^|[[:space:]])mod_unixd\.c$'; then
    printf 'LoadModule unixd_module "%s/mod_unixd.so"\n' "$modules"
  fi
  cat <<APACHE
ServerName default.test
User "#$(id -u)"
Group "#$(id -g)"
DefaultRuntimeDir "$cfg_lab"
Listen 127.0.0.1:18881
PidFile "$cfg_lab/httpd.pid"
ErrorLog "$cfg_lab/logs/error.log"
DocumentRoot "$cfg_lab/main"
<Directory "$cfg_lab/main">
    Require all granted
</Directory>
IncludeOptional "$cfg_lab/enabled/*.conf"
APACHE
} > "$cfg_lab/httpd.conf"
cat > "$cfg_lab/available/workshop.conf" <<APACHE
<VirtualHost 127.0.0.1:18881>
    ServerName workshop.test
    DocumentRoot "$cfg_lab/workshop"
    <Directory "$cfg_lab/workshop">
        Require all granted
    </Directory>
</VirtualHost>
APACHE
"$apache_server" -f "$cfg_lab/httpd.conf" -t -D DUMP_INCLUDES
"$apache_server" -f "$cfg_lab/httpd.conf" -S

The first report should list the main file without the workshop include, even though the available file is perfectly readable. The second should have no named workshop virtual host. A virtual host is a site definition that can share a program and address with other site definitions. Apache's report may show runtime settings below its host section. For this experiment it is the presence of a workshop host and its source file that matters. Each invocation uses the lab file path explicitly. Typing a bare Apache command would use its default input and may report entries for an unrelated service, defeating the purpose of the comparison.

Enable the site by creating one link in the enabled directory. Keep the backup outside that directory deliberately, with the original filename. This shows that being outside the include pattern is the property you want. Print the link destination and rerun both reports. For a second controlled observation, copy one file ending in dot bak into the enabled directory and confirm this particular pattern still chooses only the link. Even then, keep your real saved copy outside the included locations.

cp -p -- "$cfg_lab/available/workshop.conf" "$cfg_lab/backup/workshop.conf"
ln -s -- "$cfg_lab/available/workshop.conf" "$cfg_lab/enabled/workshop.conf"
cp -p -- "$cfg_lab/backup/workshop.conf" "$cfg_lab/enabled/workshop.conf.bak"
readlink "$cfg_lab/enabled/workshop.conf"
"$apache_server" -f "$cfg_lab/httpd.conf" -t -D DUMP_INCLUDES
"$apache_server" -f "$cfg_lab/httpd.conf" -S

The first output should be the available workshop file's path, which is the target of the link. The include report now shows the enabled workshop path. It should show neither backup, because one is in a separate directory and the other suffix is outside the glob. The virtual host report should name workshop.test with the enabled file and its line. A parser commonly names the link path used to open the file. Resolve that link to get the path that holds the actual content you would edit. The reports answer related questions about the path the parser opened and the site declaration created by reading it.

If you stop here, remove the lab with the cleanup block after the optional test. If you want to check a running response, confirm that no program already owns the selected loopback port. On Linux inspect the socket list mentioned earlier. On macOS an appropriate socket list can show the same information. The optional block starts Apache with the configuration you just traced and records the child identifier from this shell. Check that the process is still running and that Apache wrote the expected PID to the lab file before sending the probe. When the port is occupied the isolated process should report a bind error, and you should leave the other listener alone. Pick a different unused high port and update every lab reference together if you need to repeat the exercise.

"$apache_server" -f "$cfg_lab/httpd.conf" -DFOREGROUND &
lab_pid=$!
for attempt in 1 2 3 4 5 6 7 8 9 10; do
  if [ -s "$cfg_lab/httpd.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 "$cfg_lab/httpd.pid" ] ||
   [ "$(tr -d '[:space:]' < "$cfg_lab/httpd.pid")" != "$lab_pid" ]; then
  printf 'The lab process did not start. Here is its local error log if available.\n' >&2
  if [ -r "$cfg_lab/logs/error.log" ]; then
    tail -n 10 "$cfg_lab/logs/error.log" >&2
  fi
  exit 1
fi
curl --noproxy '*' --max-time 5 -i --resolve workshop.test:18881:127.0.0.1 \
  http://workshop.test:18881/marker.txt

Look for a 200 status and the text workshop-origin in the response body. A 200 with default-origin would show a different rule selected the file. In a configuration with just one virtual host on an address, even an unknown hostname can fall into that virtual host by default. Test the exact workshop hostname and read its parsed host declaration rather than trying to prove the whole selection rule from one successful request. When you run this lab again with two virtual hosts, put the explicit fallback first and write a third distinct marker. That gives you a clean control for unrecognized names.

Clean up when you are done. The first line runs the routine you registered earlier. The second removes the exit trap, because the routine already performed teardown. The final test proves the generated directory is gone. On a practice instance provisioned for this lesson, finish any separate cloud-resource cleanup through the normal ownership and billing workflow. This lab itself creates temporary local files and possibly one temporary local process.

lab_cleanup
trap - EXIT
test ! -e "$cfg_lab" && printf 'Temporary lab removed.\n'

Record the three before-and-after lines and your marker. A classmate should be able to tell which entry file was parsed, which include line controlled activation, what the link target was and whether a live request reached the intended site definition. If you completed the parser-only variant, write that the site was present in the parsed config without claiming to have observed a live listener. That wording identifies the boundary of your evidence and keeps the next diagnostic step clear.

Choose the next check from the evidence you already have

A real configuration investigation usually starts with incomplete information. A beginner sees a file and asks whether they ought to edit it. An experienced operator starts with the smallest observation that would distinguish two plausible causes. Here the questions are whether you have the right process, whether the intended file is in its parsed input, whether the relevant rule is selected, and whether the updated rule was activated. Your result can stop at any of these points. If you cannot yet observe a listener for the request, changing a rule for one website is premature. If the listener is known and uses the intended files, repeat the same request and follow the matching site's log before performing more filesystem searches.

Observations that narrow a configuration investigation
ObservationQuestion it answersNext comparison
A package manager lists Apache as installed.There is an installed package record.Identify the listener and service for the failing request.
A link points to the expected available file.The activation entry resolves to the intended file.Confirm the main entry's include selects that link and see its parser report.
The copied site is in the parser dump but local HTTP serves another body.The candidate parse reads it and a running process returned a response.Compare the running start options and activation result, then test the exact hostname and port.
Workshop by name returns the new marker while a raw address shows a welcome page.These requests differ in hostname and may legitimately use different definitions.Keep the hostname fixed in your controlled origin check and record the default behavior separately.
Loopback returns the new marker and the public edge returns the previous one.The origin probe reached a working local rule.Test the intended public route, including whether the edge forwarded this request to the expected origin.

Suppose the parser fails citing a file under the enabled directory. Resolve that name and see where the file came from. If the message mentions an inaccessible path, identify whether it is the configuration itself, a reference such as a log or certificate, or a content file tested later at request time. The configuration-checking account may differ from the identity handling client traffic. Do not change file permissions broadly to turn an unexplained diagnostic green. Use the specific path, service account and expected owner to identify the correct access assumptions. A shell command run as an administrator may be informative about syntax while bypassing a read restriction that the worker will encounter.

Also keep error and access logs distinct. An access log generally records observed requests and response information. An error log records operational messages such as missing paths, permission issues, or configuration errors. Startup messages may instead go to the service journal or container logs. The defaults in the initial table are leads, because a site can direct either log to a custom path and some configurations send them to standard output or disable a category. Once you know which log should record a probe, find its timestamp, client and request to connect that record to the actual response. A search string by itself can match an old request and mislead the diagnosis.

Finally, document where the investigation stopped. In a shared environment you might have permission to read a parser report but need the site owner to make a proposed change. A note that says which exact rule is selected, which source of evidence verified it, and how to run a control comparison is actionable. A note that says the configuration is wrong sends the next person back to the beginning. The ability to hand over an accurate map is useful even when you have no responsibility for activation.

Practice with a configuration discovery record

Make a one-page record about the lab instance or an approved training service. Include the machine name and where you issued the probe. List the listener and the program or unit that owns it. Quote only the relevant startup arguments and the entry path. Give one include rule, the site filename, its link target if any, and the hostname checked. Beside each item write the observation that establishes it. If your service starts from a container, write the path both inside the container and at its mounted source. If one link in the chain is still unknown, mark it unknown and name the inspection you would do next.

For a second task, open the available workshop file after running only the preparation and write steps of the lab. Predict whether adding a comment to that file would alter the list of virtual hosts. Run the report and check your prediction. Then activate the link, run the report again, and identify what changed. You should be able to explain why the syntax of the first result can be valid without the workshop being configured. Stretch task, sketch which include would pick up a backup ending in dot conf and where you would put the verified copy so either wildcard style leaves it unused.

For a peer discussion, one person says a Nginx syntax test succeeded and supplies no other details. Ask them for the binary, the arguments, and the server selection evidence. Then ask for the response marker from a request preserving the original hostname. Have them describe the exact difference between turning on an enabled link and applying a configuration to an already running process. An answer that connects both observations to an entry path and parser report is better than two memorized commands. Keep the response marker small and non-sensitive so it can be shared without opening private document content.

Interview questions and short checks

How can Nginx print a successful syntax result for the wrong site file?

The test reads files selected by the executable and arguments used for that invocation. A shell command with no startup override may check a default entry file while the service launched with an alternate entry. Even with the same entry file, the intended site file may sit outside the include patterns. Match the startup command, confirm the site file in the dump and compare the live response.

Why might a backup ending in dot bak still be read?

The include rule selects paths. That suffix stays outside a rule that selects only names ending in dot conf. If the rule matches any eligible filename or names the backup literally, it can pick up the copy. Backups outside the entire include tree are easier to reason about and preserve the original site declaration without duplicating it in the parser.

Why can a browser by IP and by hostname show different pages?

One listener can serve several names. A request using an IP address typically supplies that address as its HTTP authority and may hit the fallback declaration. Preserve the intended name when directing a probe to the same IP. Verify the response marker for that hostname, because a valid fallback response can also carry a successful HTTP status.

What does Apache's virtual host report tell you?

It describes the parsed host definitions and relevant file locations for that invocation. It can confirm that the worksheet link caused the workshop definition to enter the parser. A running worker may still have an earlier accepted configuration. The service's activation record and a targeted HTTP request provide runtime evidence.

A site's file exists under sites-available. Which evidence confirms its rules are read?

Use the main configuration's applicable include pattern and the parser report under the relevant startup arguments. An enabled link may be involved in that path. The source file's presence and a matching name alone are insufficient, because ordinary files outside the include chain do not contribute.

A source entry path starts with a service unit directory. Is this the document root?

The unit directory belongs to the service manager. The entry path for the web server comes from the program invocation, and a root selected for site content comes from a site rule. The three paths control startup, configuration, and responses at separate stages. Following them in order shows where the request behavior is defined.

The parser found the workshop host. What confirms that the listener uses it?

Observe a successful activation and send a targeted request to the intended listener with the expected hostname and path. Match the marker and status, then check the unaffected site or fallback. Merely counting workshop file names cannot tell you which branch handled traffic.

Quick quiz

  1. An available site with valid syntax is missing from the parsed report. Which observation would you collect first?

    1. The size of the site's document directory
    2. The applicable include pattern and the enabled link destination
    3. The browser's cache expiry time
    Check the first answer

    B establishes whether the parser has a path to the intended file. Content bytes and the HTTP cache become relevant after identifying the site's configuration entry.

  2. Two tests succeed. One used a bare Nginx command. One used the alternate path recorded in the service's start command. Which test is evidence about this service's candidate files?

    1. The alternate-path test, if the other startup settings were reproduced
    2. The bare command, because defaults always win
    3. Both necessarily read identical files
    Check the second answer

    A identifies the invocation tied to the service. The file check still describes the candidate on disk. A targeted request and successful activation establish runtime behavior.

  3. You found a linked site and want to save its input for recovery. Which location gives the clearest guarantee against duplicate parsing?

    1. A second dot conf file in the enabled directory
    2. A dot bak file alongside the link without checking the pattern
    3. A protected directory outside the applicable includes, with the link target recorded
    Check the third answer

    C keeps the saved bytes outside the selection even if an included directory uses a broad wildcard. Recording the link captures the second piece of state you may need to restore.

Start where the request lands

Record the destination address, port and hostname before choosing a program or file. Prove the listener belongs to that service.

Entry file and include chain

Follow the same binary and startup arguments. Use parser output to locate the exact selected files and resolve any links.

Saved files stay outside the pattern

Make a protected, verified backup of the active source. Know whether activation depends on a link as well as the file contents.

Parsed configuration and live response

Read what the candidate parser says, then use a controlled HTTP marker to verify what the running listener actually served.

Primary references