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

Chapter 6: Web Servers — Nginx and Apache

AWS Cloud

6.4 Amazon Linux 2023

Come on, let's install now. Pick the OS of your instance and type these commands with me. Today we start the first web server on Mauli Dairy's Amazon Linux 2023 server.

Nginx on Amazon Linux 2023

Identify the release, then inspect the installed package and service. Apply the full managed installation steps below only to an assigned disposable host.

cat /etc/os-release
rpm -q nginx
systemctl is-active nginx.service
systemctl is-enabled nginx.service

Apache on Amazon Linux 2023

Apache's AL2023 package and service use the httpd name. Inspect the exact unit and mapped path before choosing any change.

rpm -q httpd
systemctl is-active httpd.service
systemctl is-enabled httpd.service

Amazon Linux 2 (older)

Amazon Linux 2 used YUM and some instructions used Amazon Linux Extras. Amazon Linux 2023 uses DNF and versioned repositories. Check the current release’s supported package and its observed configuration paths.

A packaged welcome page or Server header is one observation. Verify the specific content, site and listener you intend to publish. Keep the chosen service updated under the approved maintenance plan and expose only the intended network path.

Ravindra Bagale's Tip

Check the intended local listener and response body first. A local 200 verifies that local request. Compare it with the public request’s hostname, IP, port, scheme, network path and expected content to find where the results differ.

Lab

Chala, use the isolated AL2023 exercise below. Verify the actual Nginx process’s 200 page, deliberate 404 and updated content marker on its own loopback port. Stop and clear that small preview after the checks.

Build a working response on Amazon Linux 2023

Mauli Dairy has an Amazon Linux 2023 training instance ready. Asha's first assignment is to return a known pickup message from a web server. She is tempted to copy a page into a familiar system directory and then look at the instance's public IP. That combines several decisions before she has an observation. Is this the expected operating system and package? Did the web server start? Which address and site does it serve? Is the response from the configured file? Did the public request reach that same listener? Make each question answerable before trying to publish a real site.

This lesson gives you two paths. If your training owner has assigned a disposable Amazon Linux 2023 instance for package installation, learn how to choose one package and inspect its managed service. If Nginx is already available in your learning environment, run the independent preview with an isolated configuration and a private loopback listener. That preview proves the file, port and response behavior without changing a packaged service or public firewall settings. Use the source and sample results if you do not have a suitable training host.

We will use a fixed before message and a clearly different after message. The listener is scoped to the instance itself. The exercise records one known successful request, a known missing request and a content update. Those requests teach more than looking at a banner or comparing what two package names sound like. A laptop's browser and an SSH session on an instance need separate attention. For the isolated preview, run the requests from the same machine that started the temporary process.

Write down the lesson's expected end condition. Confirm the intended program and package on Amazon Linux 2023. Read an actual HTTP status and a known body from your independent test. Confirm that the updated sample is the resource currently served. Then stop the preview and remove its own files by name. If you do an authorized package installation in a separate lab, preserve its starting package and service state so you can verify the planned cleanup.

Confirm the image release and the repository scope

Amazon Linux 2023 is a Linux distribution delivered through versions of its Amazon Machine Images and other supported distribution mechanisms. An Amazon Machine Image supplies a starting machine software environment. Different images can have different software installed and lock to different repository releases. A package command applies to the current machine. Read its release ID and repository scope before copying a command from an older Amazon Linux 2 example.

grep -E '^(PRETTY_NAME|ID|VERSION_ID)=' /etc/os-release
uname -m
command -v dnf
rpm -q system-release --qf '%{VERSION}\n'

The expected operating system fields identify Amazon Linux and version 2023. The architecture can be either a supported 64-bit Arm or x86-64 build depending on the instance. The installed release package helps identify the normal release version used by this AL2023 environment. Other package manager options or configuration may affect an individual query, so record them if they matter. A displayed package candidate belongs to the configured versioned repositories. A second AL2023 host can see another candidate under another repository release.

Use DNF as the standard package management command on AL2023. The older YUM name on AL2023 points to DNF, while Amazon Linux 2 used YUM and older package workflows. The AL2023 package repository does not use Amazon Linux Extras. If an old guide says to enable an Extras topic to obtain the package, use the current AL2023 catalogue to determine availability. Also record the intended package revision. A read-only repository query and a system-wide upgrade are independent actions. Use the distribution's documented versioned update procedure when the owner approves that maintenance.

Check the installed package before considering a candidate. An image already in use may have an older or customized web server. Its service can own the address a second process would try to use. A package can also be installed with its service inactive. A preview that uses the existing binary and a separate port does not require an upgrade merely to show a simple file response. Establish what the environment has and whether a package transaction is relevant to your assigned work.

Choose one managed package in a disposable training environment

Use this section only if a course owner assigned a disposable AL2023 host and approved package and service operations. Choose one server software package for the standard service. Nginx uses the nginx package and commonly nginx.service. Apache HTTP Server uses httpd and commonly httpd.service. The word Apache describes the software. The service unit's name is the name the Linux manager knows. If another service owns your intended socket, inspect the conflict before starting a new one. Do not stop an unrelated listener just to free a familiar port.

rpm -q nginx
rpm -q httpd
ss -ltn 'sport = :80'
dnf info nginx
dnf info httpd

Run the relevant lines separately. A missing package can make its installed query return nonzero. A repository information command can consult metadata and use the network. On an assigned offline host use its observed package records and the published package catalogue to reason about the choice. The socket check can show whether TCP port 80 already has a visible listener. The address matters. A listener on every available address can overlap one that another program tries to bind specifically. For the independent preview below, we choose a new loopback port.

On the approved disposable host, read the candidate and transaction plan. Choose only one of the following package requests for this exercise. The same command may return “already installed” or a list of planned changes. Read those results before confirming. If the package was already installed, keep a note of that starting state. An unrelated update or removal does not belong in this small installation exercise.

# Choose one package on the disposable host.
sudo dnf install nginx
# Or choose Apache HTTP Server.
sudo dnf install httpd

Next identify the installed package and the matching service unit. Query its current state. Installation can have side effects determined by package scripts and host policy. Check if the service is already active and whether it is configured for startup. If the intended disposable service is inactive and its listener is free, use its authorized start operation. Decide whether to enable it as a separate part of the exercise. A service required only for a short lab can be started without choosing boot activation.

# Nginx service only, when this is your approved disposable system.
sudo nginx -t
systemctl is-active nginx.service
systemctl is-enabled nginx.service

# Apache service only, when this is your approved disposable system.
sudo apachectl configtest
systemctl is-active httpd.service
systemctl is-enabled httpd.service

The syntax command reads the configuration that this invocation selects, and may need access to its referenced files. A failure is a reason to read the error before starting a service. Keep the unit's current state and its enablement state in your notes. If you are authorized to start the chosen inactive service, the action is sudo systemctl start nginx.service or sudo systemctl start httpd.service. Start only the chosen unit. Enable it separately only if it is meant to start according to its boot activation rules. Verify the result with a current service state, the intended listener and the actual HTTP request.

The two packaged servers have familiar starter roots and configuration locations. The usual AL2023 Nginx package layout uses /etc/nginx/nginx.conf and often a default page beneath /usr/share/nginx/html. Apache commonly uses /etc/httpd/conf/httpd.conf and the default /var/www/html for its site. Verify the actual root and site selection before uploading anything. The training fixture below supplies a different, private root. It never replaces a packaged default file. A default page can help show that a particular request got a response. Check the specific contents and listener before identifying the responder.

Read the installation plan and the package's starting evidence

Suppose the trainee chose Nginx and the package manager proposes installing the named package and several dependencies. A dependency is something the package needs to run or supply its files. A versioned repository gives the manager a catalogue of candidates. The downloaded archives and the installed database are different parts of that transaction. The plan can list the requested package, ancillary modules and shared libraries. Read the proposed version and source repository before accepting it. If an earlier release or another source is selected, inspect the configured candidate. This is the time to ask whether that source is part of the assigned image's supported setup.

After installation, query rpm -q for the chosen package again. It should report the installed release for the approved transaction. If you also locate the executable in your shell, keep the command path. The manager can use another path specified in the unit. If you are reviewing a machine with a custom installation, separate those two facts rather than assuming a one-to-one relationship. A package list can identify files installed by the vendor, while a service unit and local settings explain how they are used. The root path needed for a particular site is a separate application field.

For a planned boot configuration, confirm that the exercise actually needs a process that starts again after a reboot. Enabling a unit changes its activation setup. It does not replace checking current running state and exact content. A disposable learner may start the service for ten minutes and leave its previous enablement state alone. Another exercise may explicitly require a service that is active after boot. Write the needed acceptance condition before choosing the operation. For both cases, the current service state and a valid request matter after the start.

For Apache, a successful config test on an approved training machine checks the packaged configuration parsed by its wrapper. A real Apache deployment can include additional files, multiple virtual hosts and packaged environment settings. Collect the matching hostname and route and verify the known body the service should serve. A welcome page establishes something different from the site's own draft. When the page returned has the expected content, preserve the configuration and package context in the lab note. The same principle applies to Nginx. A default service response is a starting result that gets stronger when it can be tied to the selected site.

Give the preview its own listener, paths and process

For this exercise Nginx and curl must already be available on your learning host. Python 3 is used to choose a candidate port. Work as a normal user. We will place the configuration file, document root, temporary storage, process ID file and logs under one unique directory so nothing needs the system configuration. We will use an explicit loopback address. A process bound only to that address answers requests originating on the same host. This is the right scope for a first configuration test.

Before starting, verify the local binary. Nginx's version command is an observation. A custom command path can come from a different installation. The configuration uses the error log option supported by current AL2023 packages. If your learning system's installed binary is different, check its flags before continuing. Do not run this fixture as root to get around a configuration error. Find which path the process tried and compare it with the isolated inputs you intended.

command -v nginx
nginx -v
command -v curl
command -v python3
id -u

Use the next block for an AL2023 learning machine with those commands. The account should have its own writable home directory. The selected loopback port is held only while Python examines it. There is a short interval before Nginx binds it, so the correct response to a later address conflict is to stop and choose a new port for the isolated config. That does not justify stopping a different process. The directory's printed path lets you verify that the configuration and site files belong to the right lab.

if [ "$(id -u)" -ne 0 ]; then
  al_web_lab=$(mktemp -d "$HOME/al2023-web-lesson.XXXXXXXX") &&
    cd -- "$al_web_lab" && mkdir ./site &&
    printf '%s\n' '<h1>Mauli Dairy preview</h1>' '<p>Morning collection 06:30</p>' > ./site/index.html &&
    pwd
fi
al_web_port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1]); s.close()')

After successful setup, create the isolated configuration. The master and worker inherit your practice identity in this non-root launch. Reading the document does not exercise a different package service's identity. The events block gives a small connection setting for the lab. The HTTP block points all relevant runtime and temporary paths into the practice directory. Its server block listens on the chosen local address and port. A fixed document root and index let you predict where the handler will find the root request. No other site configuration is included.

if [ -n "$al_web_port" ] && [ -n "$al_web_lab" ] &&
   [ "$(pwd -P)" = "$(cd -- "$al_web_lab" && pwd -P)" ] && [ -f ./site/index.html ]; then
  cat > ./nginx.conf <<EOF
worker_processes 1;
pid "$al_web_lab/nginx.pid";
error_log "$al_web_lab/error.log" notice;
events { worker_connections 32; }
http {
    access_log "$al_web_lab/access.log";
    client_body_temp_path "$al_web_lab/client-body";
    proxy_temp_path "$al_web_lab/proxy";
    fastcgi_temp_path "$al_web_lab/fastcgi";
    uwsgi_temp_path "$al_web_lab/uwsgi";
    scgi_temp_path "$al_web_lab/scgi";
    types { text/html html; }
    server {
        listen 127.0.0.1:$al_web_port;
        server_name localhost;
        root "$al_web_lab/site";
        index index.html;
    }
}
EOF
  nginx -p "$al_web_lab/" -c "$al_web_lab/nginx.conf" -e "$al_web_lab/bootstrap.log" -t
fi

The process prefix and explicit config path are important. A bare command could use the package's defaults. The bootstrap log argument scopes early diagnostics where the installed version provides that flag. The configuration file scopes ordinary process logs. If the test reports successful syntax, it has checked its selected configuration and opened referenced files as needed. It has not answered an HTTP request on the port yet. If it reports a permission or directory error, read the exact path and verify your workspace before retrying.

Explain each part of your private Nginx configuration

Start at the top of the file you wrote. The worker count defines how many worker processes the preview will use under these settings. The PID directive names the file where the master writes its identifier. The error log gives a destination for startup and error observations in the ordinary instance flow. We also passed a bootstrap log path to the command for early runtime messages. A running process might use several temporary directories for handling requests and other module work. Scoping those paths avoids a dependency on system-owned directories. These settings give another learner enough information to identify your particular instance even when a packaged Nginx program is also present.

The events context has a small connection limit suitable for the lab's few requests. The HTTP context contains the logging, media type mapping and the site configuration. The media type entry tells the server which type to associate with filenames ending in html. When the body appears as text within a curl display, the browser still needs the response's media type to decide how it will handle it. The server block listens on one selected address and port. Other addresses are outside the listener's scope. This explains why two processes using Nginx can answer different requests without sharing roots or logs.

The root directive makes the document directory available as the lookup base for this site's requests. The index directive supplies a file name for a directory-shaped request. When you ask for the root path, the server selects the index inside the declared directory. When you ask for the deliberately absent file, it checks that different path under the same root and reports the missing result. This is a simple configuration with one static site. In a bigger deployment, consider location selection, explicit mappings, and any internal redirects or proxy settings before assuming the root formula applies to every route.

Notice why the private path works despite using an ordinary user's home. This preview runs under the same user's account and the files are its own. A system-managed worker running as another user may not be able to traverse that home directory. Giving everyone access to a private directory would be a much broader change than creating the correct published root under the service owner's deployment path. If a managed site's error points to an unreadable file, inspect the worker and every parent. Choose access for that intended identity and operation. Your successful own-account lab result teaches the file mapping but cannot certify another worker's credentials.

Finally inspect the startup guard. A configuration test can open or create referenced runtime files, even before a master starts. Our isolated test can leave an empty PID file. Check whether it actually has an ID and whether the process is the one your start created. A test success message does not establish a live listener. The preview waits briefly for a nonempty lab PID after an accepted start. At that point a request with the expected body completes the check. Use this same chain when teaching why files on disk can appear ready while no server currently answers.

Start the preview and verify the selected content

Check that the current directory is your lab and the syntax test succeeded. Start the temporary instance with the same explicit arguments used for the test. It normally starts as a background daemon. The following block avoids starting it again if the lab PID file already contains a value. A syntax test can create an empty PID file and temporary paths. An empty file is not a running master. If the process cannot bind the port, read the isolated error log. Confirm the first start result before sending requests or trying to choose a different port. A reported listener conflict does not concern the site's file permissions.

if [ -n "$al_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$al_web_lab" && pwd -P)" ] &&
   [ ! -s ./nginx.pid ]; then
  nginx -p "$al_web_lab/" -c "$al_web_lab/nginx.conf" -e "$al_web_lab/bootstrap.log" -t &&
    nginx -p "$al_web_lab/" -c "$al_web_lab/nginx.conf" -e "$al_web_lab/bootstrap.log"
  for al_web_check in 1 2 3 4 5 6 7 8 9 10; do
    [ -s ./nginx.pid ] && break
    sleep 0.1
  done
  if [ -s ./nginx.pid ]; then
    printf 'Preview URL: http://127.0.0.1:%s/\n' "$al_web_port"
  fi
fi

If the second command completed successfully, inspect the process ID file it wrote before continuing. It belongs inside your unique lab directory. A process ID followed by the current process listing can help show which program your launch created. Use the intended URL and known response marker as the next validation. A web listener can be live and still serve a different file than planned. We made the first marker explicit so you can compare what was sent to the client with the file you wrote.

if [ -n "$al_web_port" ] && [ -s "$al_web_lab/nginx.pid" ]; then
  al_web_url="http://127.0.0.1:$al_web_port"
  curl --noproxy 127.0.0.1 -sS -i --max-time 5 "$al_web_url/"
  curl --noproxy 127.0.0.1 -sS -o /dev/null --max-time 5 -w 'Missing HTTP %{http_code}\n' "$al_web_url/missing.html"
fi

The first response should show status 200, an HTML content type and the message with time 06:30. The second should show HTTP 404 because the fixture contains no file or handler at that path. If the root returns the wrong content, compare the running lab port and the configured document root before editing another file. A machine may have other programs on other ports. A version header can provide an extra clue, but it does not identify the active site and can be shaped by server configuration or a proxy.

Now stage a known update. Keep the first file version in your own lab, then write the new page under a new name. The new page changes one line. Compare it with the before file and predict the response. The rename under this directory replaces the earlier index entry after your approval. Nothing outside the lab shares its name. This gives you an actual change to verify without changing the Nginx configuration. Once you know which root and index apply, reading a fresh copy of that file can show the new message.

if [ -n "$al_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$al_web_lab" && pwd -P)" ] &&
   [ -s ./nginx.pid ] && [ ! -e ./index-before.html ] && [ ! -e ./site/index-next.html ]; then
  cp ./site/index.html ./index-before.html &&
    printf '%s\n' '<h1>Mauli Dairy preview</h1>' '<p>Morning collection 06:45</p>' > ./site/index-next.html &&
    mv -i ./site/index-next.html ./site/index.html
fi
curl --noproxy 127.0.0.1 -fsS --max-time 5 "$al_web_url/"
tail -n 5 ./access.log

Accept the replacement only for the path you prepared in this lab. A fresh successful request should now show 06:45. The retained prior version should still contain 06:30. In this configuration the request reads the file from disk, and we did not set up a response cache. A separately configured asset cache or proxy on a live site can change when clients see a new version. The log can show the earlier success, the deliberate missing request and the later success. Compare the requested paths and statuses to the client results. The log and response provide different evidence about the same test.

Compare evidence from the client and the server

After the root request, keep one line describing the actual listener and the exact body. For a sample with status 200, the HTTP status confirms a successful response for that request. The body confirms the preview marker. The header describing HTML confirms which content the server said it was sending. Compare those with the access log, which records the method, path and response status under the configured format. Each observation has a time. Connect the right log entry to the right client output, especially when you repeat an exercise and several root requests appear in the file.

For the deliberate missing request, the access log should show the distinct path with status 404. The server's error log may show why the request failed, such as an attempt to open a missing file. Read the actual diagnostic in your instance. It can contain a complete file path. A request's apparent missing status could also be deliberately issued by a configured location in a different deployment. That possibility is why status and error evidence are more precise together. In this specific fixture you already know the name was absent and which root the configuration used. The result verifies that controlled case.

Then find the second successful response. The same Nginx configuration now serves the changed index bytes. The access log can still show the same request path and 200 status as before. Both messages can even have the same body length because the new time has the same number of characters. The old and new contents make them different outcomes. That is why a deployment check should match the expected revision or visible marker when content changed. A simple header-only test would establish less. Measure the actual property the assignment asked to change.

A complete first-run report might include an observed client status, verified content marker, source path and one log record. Keep the file owning scope in the note. For example, note that the listener was local and the temporary instance read its own document directory. Other visitors to a live hostname may not use that same route. A course reviewer can reproduce your local experiment by adjusting the selected port and checking the known markers. This makes the result portable without relying on an exact random port or a particular Nginx version banner.

Use the observed failure to choose one AL2023 check

If the syntax test rejects a directive, preserve its exact line and file. Look at the active configuration and installed version. A quoted path or missing brace can cause a syntax error before a listener starts. A successful test does not guarantee the service can bind to the requested address or that a configured route maps to the desired file. If start fails after syntax passes, inspect the relevant process and error log under the same scope. A new config may use a different path from the one you just tested.

If an HTTP response arrives but shows the wrong page, verify the exact hostname and port. A bare loopback request can select a default site on a multi-site server. A working practice URL is separate from your packaged default service. If the requested file is absent, confirm the selected document root and index and test the actual path. If a lookup fails with permission denied, inspect which identity did the lookup and verify search on every parent plus read on the file. Compare to the runtime identity, even when your SSH login can read the contents.

AL2023 documents SELinux enabled in permissive mode by default. A customized machine can enforce a different mode. Use getenforce when appropriate and read the observed policy state. A permissive SELinux decision can be logged without preventing the action. An enforcing policy can deny a request even when ordinary mode bits look correct. Check whether the error evidence matches the specific file or network operation and relevant time. Avoid disabling a policy to diagnose an unrelated problem. File access, upstream reachability and SELinux are each separate checks.

If your local test works while a permitted outside test does not, identify the differences. The public request can use a different IP, name, TLS scheme, listener or route. EC2 security groups control allowed traffic to attached resources and are separate from host firewall rules, routing and server configuration. A listener on loopback is intentionally reachable only from that machine. A more permissive security group would not make this particular lab listen on a public address. If the task calls for public delivery, apply the separate approved design and check the actual visitor path. Verify a content marker there as well as transport reachability.

A default page or visible version string is an observation about what the client received. For a production site, keep packages under the organization's update process, review which services and ports need to be available and verify the correct site after an approved publication. Some deployments choose to limit version disclosure through documented configuration. That choice is separate from maintaining and validating the service. Choosing a header policy should not replace confirming that the actual response is correct.

Stop the owned preview and check what remains

When you have the expected response and log evidence, use the matching configuration to stop the temporary process. The signal command reads the PID path specified by that configuration. The guard checks the exact practice directory and the file that belongs to it. The quit request lets the Nginx master perform a graceful shutdown. It can take a moment while existing work finishes. Check for the disappearance of the lab PID file before removing its paths. This is a different lifecycle from the distribution-managed service.

if [ -n "$al_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$al_web_lab" && pwd -P)" ] && [ -s ./nginx.pid ]; then
  nginx -p "$al_web_lab/" -c "$al_web_lab/nginx.conf" -e "$al_web_lab/bootstrap.log" -s quit
fi
ls -la -- .
ls -la -- ./site

If the PID file is still visible, wait briefly and check whether it disappears, or inspect the relevant process and log rather than sending a broad signal. The preview's assigned port can normally be reached no longer once the listener closes. The cleanup below assumes the complete successful exercise, including the site replacement. Inspect the remaining list if you stopped early. Remove only the particular artifacts you created. If the rename was declined, the staged file may still be present in the site folder.

if [ -n "$al_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$al_web_lab" && pwd -P)" ] && [ ! -e ./nginx.pid ]; then
  rm -i -- ./nginx.conf ./bootstrap.log ./error.log ./access.log ./index-before.html ./site/index.html &&
    rmdir -- ./site ./client-body ./proxy ./fastcgi ./uwsgi ./scgi &&
    cd -- "$HOME" && rmdir -- "$al_web_lab"
fi

Answer each prompt only for the known practice file. An empty directory removal will stop if unexpected files are present. File locations may vary if a startup error prevented normal logging. Use the observed names rather than running another command against a broader path. If you did the separate package installation on a disposable machine, handle its cleanup through the assignment owner. Preserve anything that existed before the exercise. A temporary standalone preview needs only its own shutdown and file cleanup.

Choose and explain one follow-up experiment

Use these prediction tasks after completing the first valid run. Work in another private practice directory if you want to repeat a changing operation from the beginning. Preserve the result from your earlier run. For each case write the first observation you would collect and the result that would distinguish two plausible causes. Try to answer with one real check instead of a list of every web command you remember.

  1. The given port reports connection refused, and the syntax test printed success. Check the dedicated PID file and the process started by that configuration before changing a content file. If the file exists but is empty, find whether only validation happened. Then read the configured bootstrap or error log. An address conflict would require selecting another independent port. A missing file or access issue before startup points to the specific path in the diagnostic.

  2. The confirmed preview answers 200 at the root, but the time is 06:30 after you tried the update. Read the exact destination and its staged sibling. The interactive move could have been declined, leaving the newer file under its temporary name. Compare the destination with its before copy and read the last successful request. If the local destination is newer but the returned body is old, confirm the request reached the right listener and whether any intermediary is involved. For this fixture there is no configured response cache.

  3. The preview works on the instance but the same loopback URL on the laptop fails. Name which machine the loopback address belongs to in each case. The browser ran on another system and asked that system for the selected port. Repeat the request from the machine that started the process. A real public site has a separate designed route and controls. Installing a package again will not change which machine a loopback address reaches.

  4. The packaged Apache service reports active when you expected to test Nginx. Compare their respective package and service names, then identify the particular address and port each is configured to use. A 200 from the default address alone can be Apache's response, the expected separate site or another handler. Use a body marker from the intended resource and the exact route to know. This question can be answered without stopping anyone's service.

For your own lab handover keep one before record, one after record and a cleanup result. The before record can show the first successful body and retained version. The after record can show the new body under the same URL. The cleanup outcome can state that the owned master no longer had its lab PID file and the expected directory was removed. If an extra file remains, identify it explicitly. A verified scope and known results make your experiment useful to a teammate even when their package version or image is different.

Interview questions with worked answers

Why do you use DNF in an Amazon Linux 2023 lab?

It is the distribution's documented package manager. The YUM compatibility name can point to DNF on that release. I verify the actual OS and versioned repository, then inspect the candidate. I avoid applying an older Extras-based AL2 procedure to this environment.

Can you test a web server without exposing the instance?

Yes. Bind a deliberately scoped listener to loopback and send the request from that same host. The preview keeps its own configuration, document path, PID and logs. I verify the exact content and clean up the owned instance. An outside visitor path is a separate test.

What evidence do you collect when nginx -t succeeds but the service won't answer?

I confirm which configuration the test read and whether the intended service started on the expected address and port. Then I inspect the relevant start error and send the precise local test if the listener appears. A successful parse does not exercise a customer request or prove a port is available.

What does permissive SELinux mean for a troubleshooting check?

SELinux can log a denial it would enforce in enforcing mode. It does not block the action in permissive mode. AL2023 documents that default, but I verify the actual mode and look for evidence tied to the operation. I also check ordinary permissions and route handling.

Why did the preview show a later file version without reloading Nginx?

We replaced the selected static index file in its configured root. This fixture reads the file for a new request, without a configured response cache. The site configuration itself did not change. I verified the new body and the retained older file to demonstrate the result.

Check your understanding

1. Which fact do you confirm before applying older Amazon Linux package instructions?

A. The operating system and release plus its documented package tool
B. A random public page title
C. The web console window size

Answer and reasoning

A. AL2023 uses a different repository workflow from AL2. Match the release and installed tool first.

2. The web preview is bound to 127.0.0.1. Where does its test work?

A. From any public address if a security group permits it
B. From the host running that loopback listener
C. Only in a browser on another computer

Answer and reasoning

B. Loopback is local to the machine. Your laptop and the EC2 instance have separate loopback addresses.

3. The syntax test passes. Which next result verifies the actual response?

A. An enabled unit by itself
B. An earlier version header from another site
C. A request to the intended listener returning the expected content marker

Answer and reasoning

C. A loaded and working route must answer the actual request. The syntax test verifies a different step.

4. What should you do when a new isolated listener reports its chosen address is already in use?

A. Review the scope and use another independent port after confirming the conflict.
B. Stop all web processes by name.
C. Change the document's file extension.

Answer and reasoning

A. The conflict concerns the socket. Preserve existing services and keep the preview on its own listener.

5. Which observation distinguishes a verified static content update from a config change?

A. The contents changed at the selected file and the same scoped route returns the new marker.
B. The package index reports another release.
C. A different host returns any status.

Answer and reasoning

A. The known path and response connect the content replacement to the intended live handler. This exercise did not change the configured route.

Revision cards

Confirm AL2023 first

Read the actual release and use DNF. A versioned repository provides candidates for its configured scope.

Package state and service state

Verify the installed package, chosen unit, current operation and enablement separately. Check the actual request as its own result.

Isolate your preview

Use a dedicated loopback port, config, PID, document root and logs. Start and stop the instance with matching settings.

Match the content

Check status, media type and a marker from the intended route. Verify that a deliberate missing request is separate.

Verify the access layer

Identify the account, path, local listener and intended network. Use actual SELinux and firewall states rather than assuming the defaults.

Keep a before version

Compare the original and changed page. Confirm the new response, preserve useful evidence and clear only the known practice files.

Official references