Chapter 6: Web Servers — Nginx and Apache
6.5 Ubuntu 22.04 / 24.04
Friends, Ubuntu uses apt for packages. After installation check the service’s actual state. Ubuntu’s packaged sites commonly become configuration inputs through links from sites-enabled to sites-available.
मित्रांनो, Ubuntu वर packages साठी apt वापरतो. Install झाल्यावर service ची actual state तपासा. Ubuntu package च्या site files साधारण sites-available मध्ये असतात आणि sites-enabled मधील links ने निवडल्या जातात.
दोस्तों, Ubuntu पर packages के लिए apt इस्तेमाल करते हैं. Install के बाद service की actual state देखो. Ubuntu package की site files आम तौर पर sites-available में होती हैं और sites-enabled में links से चुनी जाती हैं.
Nginx on Ubuntu
Confirm the package, its current unit and its enabled site links. The worked exercise below uses a completely separate Nginx instance.
dpkg-query -W nginx
systemctl is-active nginx.service
systemctl is-enabled nginx.service
ls -l /etc/nginx/sites-enabled/Apache on Ubuntu
Inspect the Ubuntu Apache package and unit. Use its packaged configuration test in the authorized environment before applying a change.
dpkg-query -W apache2
systemctl is-active apache2.service
systemctl is-enabled apache2.serviceApache packaging helpers used on Ubuntu
| Command | Purpose |
|---|---|
sudo a2ensite mysite.conf / a2dissite |
Enable / disable a virtual host |
sudo a2enmod rewrite proxy proxy_http / a2dismod |
Enable / disable modules |
sudo a2enconf / a2disconf |
Enable / disable extra config snippets |
Ubuntu firewall (ufw)
Check the host’s actual UFW status if it is installed and the inspection is authorized. The EC2 security group and host firewall are separate layers. Before any approved firewall change, verify the real management path and its permitted access. The loopback exercise needs neither firewall changed.
Ravindra Bagale's Tip
Before an approved firewall change, confirm the real SSH port or management method, authorized source and recovery path. Verify the listener and the applicable cloud and host policy separately. The local exercise uses a loopback listener.
Ravindra Bagale's Tip – मराठी
मंजूर firewall बदलाआधी नेमका SSH port किंवा management method, authorized source आणि recovery path तपासा. Listener, cloud policy आणि host policy वेगवेगळे बघा. Local exercise loopback वर आहे.
Ravindra Bagale's Tip – हिंदी
मंज़ूर firewall बदलाव से पहले सही SSH port या management method, authorized source और recovery path देखो. Listener, cloud policy और host policy अलग-अलग जाँचो. Local exercise loopback पर है.
Lab
Chala, check your assigned Ubuntu package and enabled site link. In the worked exercise below, verify the same named request before and after enabling the lab link, then after applying the isolated reload.
Prove which Ubuntu site configuration is in use
Mauli Dairy's Ubuntu lab already has a web server responding. Asha prepares a file describing the new pickup site. She saves it under a directory called sites-available and expects the browser to show it. The browser still displays a welcome page. The change on disk was real. The practical question is whether the running web server includes that file and chooses its site for this request. We can answer by tracing the available configuration, the enabled configuration and an actual response.
Ubuntu's packaged Nginx and Apache commonly use available and enabled directories for sites. A site file describes behavior. An enabled link selects a file for the configuration tree when the appropriate include matches it. A running process reads a configuration when it starts or when an appropriate reload applies it. The incoming hostname and listener then select the active site. Saving a file, selecting it, applying it and seeing its response are four observations. Confusing those stages explains why students often keep editing a file that their request has never used.
Our main practice uses the installed Nginx binary with a private version of that directory layout. The lab sets up a fallback response and keeps the named pickup site available but initially outside the included set. We will observe the response before and after creating a link and again after reloading the private process. You can run it on a Linux training host with the required binary, including Ubuntu 22.04 or 24.04. The system packages and services remain outside the lab. If you have only an Apache package, read the sample observation and use the matching Ubuntu package reference to understand its workflow.
There is also a short managed package walkthrough for a separately assigned disposable Ubuntu host. Use it only where package and service operations belong to your exercise. Keep those operations separate from the independent lab. In a classroom with a shared instance, ordinary read-only observations and a private loopback process can teach the difference without changing a real website.
Confirm the release and inspect the package before choosing it
Ubuntu 22.04 and 24.04 are distinct releases. They usually provide the same family of package tools and service names for these examples. They can supply different builds, package files, module versions and locations for vendor unit definitions. Check the actual release and architecture before using instructions. A running host can contain local changes that differ from the base image. The installed package database and current systemd properties provide more evidence than the release name alone.
grep -E '^(PRETTY_NAME|ID|VERSION_ID)=' /etc/os-release
uname -m
command -v apt
command -v systemctl
The first output should name the expected Ubuntu release on that host. The command path checks show whether your shell can find those programs. A container may have apt while the usual system manager is unavailable. In that case verify the environment's actual process startup method. If the local terminal is on your laptop and the lesson target is remote, run the release and service checks in the intended session. What a local package query sees cannot determine the state of a different server.
APT can read a package position from its local index. You might have a candidate advertised before it is installed. An installed query or service state can distinguish what is already available. On a protected machine, perform the read-only query before suggesting any package change. Package contents may be split. For instance, the common Nginx package can supply configuration while a binary package supplies the executable. Identify which package owns the file you are looking for. Do not infer from one absent path that no package exists.
apt-cache policy nginx apache2
dpkg-query -W -f='${Status} ${Version}\n' nginx apache2
dpkg-query -L nginx-common | grep -E 'nginx\.conf$|sites-available/default$|nginx\.service$'
Run the installed listing for the relevant package. It can report a missing package or a non-installed state, which is useful evidence. The file list shows what the package database associates with that package. It does not prove the running service uses the listed input. Ask whether the current request reaches a separately configured site or another installation. The release and package names are still valuable because they point you to the local test command and packaging conventions.
Use managed package commands only on the assigned disposable host
On a system where the owner has approved installing a web server, choose one for the intended listener. Refresh the package catalogue when the exercise permits it. Read the distribution's proposed transaction and existing socket evidence. An upgrade changes installed programs and is a separate operation. The usual package requests for this lesson are named nginx and apache2. If the familiar address or port is already in use, inspect it before starting another service. Do not stop a different website to make a training test work.
# Choose one package, on the approved disposable system.
sudo apt update
sudo apt install nginx
# Alternative package, if that is the assigned server:
# sudo apt install apache2
Some Ubuntu package installations try to start the service automatically. The result can depend on package scripts, policies, pre-existing listeners and whether systemd is available. Verify its current state instead of assuming a service has started. Check whether boot enablement is required for the exercise. An inactive service and a disabled unit are separate states. When an action is authorized, choose the exact unit and verify both the start and the local request. A 200 from an unrelated default host does not satisfy the test.
# Choose the installed unit for your assigned Ubuntu service.
systemctl is-active nginx.service
systemctl is-enabled nginx.service
systemctl is-active apache2.service
systemctl is-enabled apache2.service
For Nginx, the typical packaged starting configuration is under /etc/nginx. For Apache it is under /etc/apache2. If the service is already running, inspect the site and listener before applying changes. Use nginx -t for the appropriate Nginx configuration and apache2ctl configtest for the packaged Apache's config where your authorized environment allows it. Both can need access to configured files. The fact that the syntax is accepted says nothing by itself about whether a new worker already applied the configuration. Observe the actual named response as a separate check.
Read the state immediately after an Ubuntu installation
Imagine that your authorized setup just completed the Nginx package transaction. Apt reports the package and its dependencies installed. A separate shell query for the unit may show a different kind of result. If the unit is active, it could have been started during installation, by an earlier manual start or under an established boot setup. If the unit is inactive or failed, use the current manager state and its diagnostic before assuming an installation error. In some environments, package scripts cannot start a service because a policy or container setup forbids it. A TCP socket already occupied by an earlier service can prevent a valid package from starting its default listener.
Capture the actual status rather than repeating the install command. Query the correct service name based on the installed package. If it shows failed, inspect a bounded set of the relevant unit logs, assuming your assigned host permits that read. A log can tell you whether the startup hit a bind conflict, a syntax problem or a missing file. Compare the expected port with a read-only listener inspection. Take care with an unprivileged view: it may show which sockets exist without exposing process ownership information. Ask the system owner when a listener belongs to an existing site.
Once your assigned service is verified on its intended test socket, send the local request. Expect a response from the correct local name and route, and verify a body marker if the lesson asks for published content. Seeing an Ubuntu welcome page is evidence about the default response. It leaves open whether the named application was selected. The package can ship files in several places, including a reusable reference HTML file and the default site's working root. Follow the effective site definition before deciding where to write. File names derived from Debian packaging can appear on Ubuntu, which is part of its packaging relationship. They are clues rather than an authoritative inventory.
For a short course assignment, boot persistence might be unnecessary. If a service is started temporarily, record its initial enabled state and keep any planned changes to the unit in scope. Enablement concerns activation under the unit's configured install rules. It differs from an immediate start. For an approved lab requiring persistence, check the exact state after applying the planned policy and again after the event the exercise intended to support. This choice does not alter which enabled virtual host answers a request. You still verify the site and listener. Write the two forms of enablement separately in your notes.
If the release's package candidate is absent, review the distribution, repository and index state. An authorized index refresh can update knowledge about what is available without installing a different program. Validation and version checks follow the installed result. Avoid treating a package lookup issue as evidence of malformed site configuration, since the site file is not involved in that lookup. Making the diagnostic one step at a time helps keep a routine package issue from becoming an unrelated deployment change.
Follow which available file becomes an included input
An available directory is a common organization technique. It can hold complete candidate definitions alongside a package's default site. A symbolic link in an enabled directory can point to one of the available files. The link is a filesystem entry recording another path. For a relative link, the name is interpreted from the containing directory, so a link whose stored path begins with two dots walks to its parent before finding the available file. Listing a link and reading the target tell you which site definition the selected entry refers to.
The main configuration uses an include directive with a path or pattern. If it matches the enabled link, the server reads the target through it when it processes configuration. An available file outside that include path can stay on disk indefinitely without becoming an input. A broken link or a name the include does not match can produce an error or be left out. Observe the actual include rule. Some package setups include all names in the enabled location. In our isolated lab we deliberately use a pattern ending in .conf so the selection is visible.
For the Ubuntu Nginx package, inspect /etc/nginx/nginx.conf and the enabled directory where configured. For Apache, its packaged main configuration can include sites-enabled as well as directories for configuration snippets and modules. The a2ensite helper creates the site's enabled link under the distribution layout. Its paired tool removes that link. The existence of the enabled link prepares the appropriate configuration input. A running process still needs to read and apply the new configuration. Verify which virtual host a request actually selected after the permitted action.
Consider a real site upgrade. A copied backup under a matching include pattern can cause a second definition to be read, while a backup outside the include tree does not participate. A change to a target file can affect several links if they refer to the same file. Before editing, check where the file is used. Keep before versions in your approved backup location and verify the relevant selected files. These checks help preserve other sites whose server process shares the top-level configuration.
Trace the equivalent Ubuntu Apache workflow
The Apache package on Ubuntu usually has an entry configuration file under its Apache directory and includes other inputs. A release can organize ports, module loaders and sites into separate files. A port configuration says where the program accepts connections. A virtual host block groups rules for a particular site on a listener, and its server name helps select it. A selected virtual host and an available listener both matter. A site definition alone does not change which port the process listens on. If the application requires a new listener, use the matching approved Apache configuration and verify that it is available.
The packaged a2ensite utility operates on the site's available file and creates the corresponding enabled link. a2dissite removes the selected link when you turn off that site's configuration under an approved procedure. These helpers change configuration selection. They do not start a new daemon and do not change the web root files. Take a learning case with a prepared file named pickup.conf. Before using the site helper, identify the hostname and listener in that file, and verify the intended document path. After enabling it, test the complete configuration and apply it through the approved service management step. Then send the expected hostname and path to the actual listener.
Some requirements belong to modules rather than sites. The a2enmod helper selects module loaders and related configuration under the module directories. A module can add a directive or handler, such as features used by certain rewrite or proxy rules. Check the specific requirement before changing the enabled module set. A static page can often be served with the existing package setup. If another site already needs a module, removing it can affect that site too. The a2enconf family selects shared configuration snippets under the package's configuration layout. Write down which of those objects you intend to enable and what observable behavior it changes.
For validation on a disposable Ubuntu setup, use the distribution's apache2ctl configtest in its intended environment. The package wrapper can supply environment details referenced by main configuration. A configuration snippet that relies on one of those details may not run independently on another machine. For a known website, a relevant virtual-host summary can help you trace names, defaults and their input file and line. Read those summaries only in an authorized context. They can contain configuration paths for other sites. The evidence you share should describe the target listener, hostname and path from your assignment.
After a verified apply, demonstrate one reason the site was chosen. A name that matches the intended virtual host normally gives its own configured result on the selected listener. A bare IP or another name can select a default virtual host. The default can be the first selected definition for the matching socket according to Apache's matching rules. Do not mistake this fallback result for a DNS change. DNS can deliver an address. The program still chooses an HTTP site for a name and listener. If the exercise uses HTTPS, the correct TLS name participates earlier in the connection. Test from the relevant client context rather than assuming a changed configuration applied globally.
The only configuration work in the independent Nginx lesson is under one temporary directory. It lets you demonstrate the same broad stages without assuming the Ubuntu Apache module paths or environment. If you want to compare the two, describe which command creates a site link in the packaged Apache workflow and which path the Nginx example uses for its include. In both cases remember that selecting a candidate input, applying it and visiting the intended site are distinct events.
Create an independent preview with only the fallback enabled
For this exercise you need Bash, Python 3, curl and an installed Nginx with the documented prefix, config and error-log options. Use a normal non-root account. Everything takes place in a private temporary folder. Setup uses a high loopback port; it may be taken by another process in the brief time before Nginx binds it. If binding fails, review the lab error and choose another port for this independent instance. Keep all configuration and runtime paths in the same practice directory. Stop if the setup does not print that path.
Check the installed binary before this loopback exercise. Nginx added the command-line error-log switch used here in version 1.19.5. Ubuntu 22.04's standard package series is based on 1.18, so its binary can lack that switch. A newer approved build or a different assigned host can support it. The setup tests the switch together with the help command and exits the setup path if that prerequisite is missing. This is a check of the tools already available, with no request to change repositories or install a second binary.
On a host without that switch, follow the read-only package and unit checks above. Then use the earlier course local inventory model to verify the enabled link, or follow the four response stages in this lesson's observation table. You can still explain the difference between a selected file and a running configuration from the model. If you have a disposable Ubuntu host that already has the packaged service available, use its documented, approved configuration workflow for a real retest. Apply only the course environment's procedure for that host.
For a compatible installed binary, all preview paths below belong to one directory. The error-log switch gives the binary a scoped log at invocation, even for early messages before it reads the isolated configuration. Later Nginx logs follow their paths in that configuration. Having two paths in the fixture helps you recognize which messages came from initial validation and which came from the running process.
unset ub_web_lab ub_web_port
if [ "$(id -u)" -ne 0 ] && command -v nginx > /dev/null &&
command -v python3 > /dev/null && command -v curl > /dev/null &&
nginx -e stderr -h > /dev/null 2>&1; then
ub_web_lab=$(mktemp -d "$HOME/ubuntu-web-lesson.XXXXXXXX") &&
cd -- "$ub_web_lab" && mkdir ./sites-available ./sites-enabled ./pickup &&
printf '%s\n' 'Pickup site enabled: 06:45' > ./pickup/index.txt &&
pwd
ub_web_port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1]); s.close()')
else
printf '%s\n' 'Use the read-only exercise if the installed tool or mode is unavailable.'
fi
The top-level configuration below refers to two possible server definitions but reads only the included set. The fallback and named site files exist in the available location. Initially, only fallback has an enabled link. The two server blocks would use the same local listener under one Nginx process. Once loaded, Nginx can select the named pickup server using the request's host field. We intentionally use plain HTTP on a private loopback port so that this exercise does not depend on domain registration or a certificate.
if [ -n "$ub_web_port" ] && [ -n "$ub_web_lab" ] &&
[ "$(pwd -P)" = "$(cd -- "$ub_web_lab" && pwd -P)" ] && [ -f ./pickup/index.txt ]; then
cat > ./nginx.conf <<EOF
worker_processes 1;
pid "$ub_web_lab/nginx.pid";
error_log "$ub_web_lab/error.log" notice;
events { worker_connections 32; }
http {
access_log "$ub_web_lab/access.log";
client_body_temp_path "$ub_web_lab/body";
proxy_temp_path "$ub_web_lab/proxy";
fastcgi_temp_path "$ub_web_lab/fastcgi";
uwsgi_temp_path "$ub_web_lab/uwsgi";
scgi_temp_path "$ub_web_lab/scgi";
default_type text/plain;
include "$ub_web_lab/sites-enabled/*.conf";
}
EOF
cat > ./sites-available/default.conf <<EOF
server {
listen 127.0.0.1:$ub_web_port default_server;
server_name _;
return 200 "Preview fallback";
}
EOF
cat > ./sites-available/pickup.conf <<EOF
server {
listen 127.0.0.1:$ub_web_port;
server_name pickup.example.test;
root "$ub_web_lab/pickup";
index index.txt;
}
EOF
ln -s ../sites-available/default.conf ./sites-enabled/default.conf
fi
Read what you created before starting. We have one fixed root for the pickup content and a fallback that returns its own text directly. The fallback marker lets us tell which rule answered. A default server can answer an unknown hostname on the configured socket. The pickup hostname in the test is reserved for examples. Curl sends it in a request to the local listener, so it does not require a live DNS record. Describe the expected before result now: the pickup-named request will get the fallback while only that server is included and active.
ub_nginx=(nginx -p "$ub_web_lab/" -c "$ub_web_lab/nginx.conf" -e "$ub_web_lab/bootstrap.log")
ub_web_url="http://127.0.0.1:$ub_web_port/"
if [ -n "$ub_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$ub_web_lab" && pwd -P)" ] &&
[ ! -s ./nginx.pid ]; then
"${ub_nginx[@]}" -t && "${ub_nginx[@]}"
for ub_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
curl --noproxy 127.0.0.1 -fsS --max-time 5 -H 'Host: pickup.example.test' "$ub_web_url"
printf '\n'
fi
fi
The Bash array keeps the command and its scoped arguments together. All calls use the same prefix, config and bootstrap log. Configuration validation can create an empty PID file. The start check distinguishes nonempty from merely present. When the process is ready, the request should display Preview fallback. If it does not, read the local log and check the exact path and port of your fixture. The test exercises the hostname and content, while the syntax command checked a different condition.
Observe a link on disk before and after a reload
Now create the second enabled link and repeat the same request before applying a change. The file is present and its configuration is available for a future parse. The running workers still handle requests according to the configuration they already loaded. Compare the visible link and the unchanged response. Keep the URL and Host field exactly the same. This is the useful comparison because it holds the request constant while the configuration stages change.
if [ -n "$ub_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$ub_web_lab" && pwd -P)" ] &&
[ -s ./nginx.pid ]; then
ln -s ../sites-available/pickup.conf ./sites-enabled/pickup.conf &&
ls -ld -- ./sites-enabled/pickup.conf &&
curl --noproxy 127.0.0.1 -fsS --max-time 5 -H 'Host: pickup.example.test' "$ub_web_url"
printf '\n'
fi
The listing should name the available pickup config as the link target. The response should still be the fallback. This is where a student can show a correct enabled file and still be looking at the older live behavior. The next step is a validation and reload of only the private instance. If the validation fails, preserve the error and correct the candidate instead of forcing another operation. The running process is available to inspect under its earlier configuration.
if [ -n "$ub_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$ub_web_lab" && pwd -P)" ] &&
[ -s ./nginx.pid ]; then
if "${ub_nginx[@]}" -t && "${ub_nginx[@]}" -s reload; then
for ub_check in 1 2 3 4 5 6 7 8 9 10; do
if body=$(curl --noproxy 127.0.0.1 -fsS --max-time 2 -H 'Host: pickup.example.test' "$ub_web_url") &&
[ "$body" = 'Pickup site enabled: 06:45' ]; then
printf '%s\n' "$body"
break
fi
sleep 0.1
done
curl --noproxy 127.0.0.1 -fsS --max-time 5 -H 'Host: unknown.example.test' "$ub_web_url"
printf '\n'
fi
fi
The expected named result is Pickup site enabled: 06:45. The unknown name should still receive the fallback text. The reload request goes to the master whose lab PID is in this configuration. New workers can take over the new configuration while old workers finish existing requests. We briefly wait for the expected marker rather than assuming the first instant after a signal always represents the completed transition. If the marker never appears, inspect the error log and the selected include. Record what the responses established.
In this lab both the fallback and named site can use the same status. Matching the content makes their behavior distinguishable. The old response after the on-disk link was created shows the effect of a configuration remaining loaded in memory. The later response after the validated reload proves this request matched the added site. The unknown-host result establishes that the default remains separate. Neither proof depended on a command that changes another site's server process.
Use a small matrix to diagnose the site that responded
The isolated experiment gives a particular sequence of outputs even though every response is 200. With only the fallback selected, the pickup name receives the fallback body. Adding the link still leaves the loaded configuration unchanged. After the validated reload, the same name receives the pickup file. An unknown name continues to receive the fallback. Write these four observations in a table. Include which link exists and which configuration you believe was loaded at each stage. The matrix separates the stage where the input changed from the stage where a user could see the effect.
| Configuration stage | Request name | Expected body |
|---|---|---|
| Fallback selected before first start | Pickup name | Preview fallback |
| Pickup link on disk before reload | Pickup name | Preview fallback |
| Validated configuration applied | Pickup name | Pickup site enabled with the new marker |
| Same configuration after apply | Unknown name | Preview fallback |
If the first output differs, inspect the independent config file and the exact listener you reached. A listener conflict could have sent your test somewhere else if you did not verify the dedicated PID and startup. If only the third step differs, check the enabled link target and include spelling. A relative link depends on the directory it is in. If the syntax test fails, it can name the invalid input. Read that file and verify the correction before reapplying. If the syntax test passes and the old response persists, check whether the intended master received the reload and read its isolated error log. Observe the response again after the operation completes.
One helpful recovery exercise is to describe the state you would restore if the pickup configuration had a mistake. In the local lab the fallback definition remains available. The additional enablement consists of one known selected link. An authorized recovery can remove that selected link after identifying it, confirm the resulting include tree and apply the earlier working configuration. The available source can stay for repair. The retry check is the same hostname and port returning the expected fallback. This is a small example of reverting a configuration selection while preserving the candidate file for diagnosis.
Include a path query and a name query in your troubleshooting note. A path query inspects which file an enabled link reaches. A name query asks the listener with the intended request hostname. Their output can seem to conflict when a newly selected link has only just been created. That outcome is useful if you can say which observation concerns the disk and which concerns the running service. The logs can corroborate which request arrived at the process you own.
Explain which network controls an outside request uses
Ubuntu provides UFW as a way to manage a host firewall when installed and configured. Its observed state depends on the image and owner. An AWS security group governs traffic for its associated network resources. That is a different layer from any host firewall. The public path can also depend on address, route, listener and TLS configuration. This local lab needs no firewall adjustments. The loopback listener is meant to be reached from the same host. Opening a public rule would not make a loopback listener serve a different interface.
If an authorized assignment includes an outside test, establish a permitted source, destination and service port with the host owner. Verify the existing admin access route, including the actual SSH port or management method, before any firewall changes. A default application-profile name does not prove it matches the expected listener or the restrictions the project needs. Hosts can use different policy tools. Read the current policy and request path rather than enabling a firewall from a command copied into a web exercise. Inspect only the scope you are allowed to check.
A loopback test returning a good page is useful evidence. If the outside name fails, confirm the destination address, scheme and port, then compare with the active listener and relevant network controls. If the outside request reaches another site or a default page, examine the host selection and proxy path. Network rules determine reachability. The selected rule inside the web server determines what it will return for an accepted request. The exact error and response identify which part to check next.
Interpret a failed public request without changing firewall state
Consider three learners reviewing the same Ubuntu training instance. The first used curl against a known loopback port and got the expected page. The second used the public hostname and saw a connection timeout. The third used the public hostname on another machine and saw a different welcome page. Those three pieces of evidence can all be real. The first is scoped to a local process and site. A timeout needs an independent check of the public IP or endpoint, route, protocol and listening address. A welcome page shows that some endpoint replied and requires knowing which host and path were selected.
For an authorized cloud exercise, check the associated security group and whether traffic is allowed from the intended source to the selected destination port. The local host can apply additional firewall policy. UFW is one way of managing such policy on Ubuntu, and its state may be inactive, active or managed by the image owner. An inactive UFW frontend does not prove all traffic is permitted, since other firewalling or service binding can apply. A local listener can remain bound only to loopback. Use the actual network path rather than treating the firewall status as the whole route.
For an authorized host inspection, a command such as sudo ufw status verbose can show the state and rules where UFW is installed. This is a query in its documented workflow. It may require elevated permission to read the policy and may not be appropriate on a shared system without that access. A host owner who plans any change should preserve their known management route and maintain a recovery method. Use the actual SSH port and trusted sources rather than blindly assuming a packaged profile represents the setup. The lesson does not require modifying either firewall for the loopback exercise.
Separate a confirmed HTTP refusal from a connection failure. A 403 response says that a responder refused the request. It can arise from an application or file access rule. The response reached your client through some network path. A timeout before any HTTP response can require a connectivity check, but an application or proxy can also delay a response after a connection succeeded. Read the client error and timing. If details show an HTTPS certificate mismatch, verify the intended name and endpoint rather than treating it as a file access error. Use the observation to choose the part of the system that can explain it.
Finish with a brief handover for an outside test. State the client network and intended hostname, port and scheme. Include the observed status or earliest error and a safe content marker if available. Explain how this differs from the local check. If authorized information is missing, name the check that would narrow it rather than broadening the firewall. The exact route and evidence will help the person responsible for the affected layer decide.
Stop and remove the isolated instance
When the result is verified, stop the process using the same scoped command array. Wait for its PID file to disappear. If it remains, inspect the lab error log and identified process rather than sending a broad signal. The successful cleanup assumes the two enabled links and both site files exist. Inspect your actual files and omit an absent item if you stopped earlier. Remove only known scratch paths. Keep any notes outside the folder.
if [ -n "$ub_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$ub_web_lab" && pwd -P)" ] &&
[ -s ./nginx.pid ]; then
"${ub_nginx[@]}" -s quit
fi
ls -la -- . ./sites-available ./sites-enabled ./pickup
if [ -n "$ub_web_lab" ] && [ "$(pwd -P)" = "$(cd -- "$ub_web_lab" && pwd -P)" ] &&
[ ! -e ./nginx.pid ]; then
rm -i -- ./nginx.conf ./bootstrap.log ./error.log ./access.log ./pickup/index.txt \
./sites-enabled/default.conf ./sites-enabled/pickup.conf ./sites-available/default.conf ./sites-available/pickup.conf &&
rmdir -- ./pickup ./sites-enabled ./sites-available ./body ./proxy ./fastcgi ./uwsgi ./scgi &&
cd -- "$HOME" && rmdir -- "$ub_web_lab"
fi
Answer the confirmation prompts for your sample paths only. Empty-directory removal makes unexpected entries visible by declining to remove the directory. If a configuration test ran but there is an empty test PID file and no master was launched, identify that empty artifact before clearing it. Do not treat its presence as evidence of a process. If you ran the separate package installation path on a disposable host, follow its approved recovery or retirement procedure and preserve the starting state when appropriate.
Interview questions with worked answers
What is the relationship between sites-available and sites-enabled?
The available location can hold site configuration. An enabled link can select one of those files for the main configuration's include rules. The configured include and a successful apply determine whether it is effective. I verify the matching hostname and response after the intended load.
Why did the page stay the same after adding a symlink?
The live process still used its previous configuration. The link changed the future configuration input. I first checked the target and syntax, then reloaded the isolated server and verified a changed response to the same request.
How does Apache's a2ensite differ from enabling its systemd service?
The site helper selects a site file by creating an enabled link in Ubuntu's Apache packaging layout. Systemd enablement affects unit activation, often at boot. I verify both the daemon state and the named site's actual behavior independently.
What do you check after installing a package on Ubuntu?
I check the installed package, actual service name, current state and listener. Installation can attempt startup according to local policy. I separately verify the intended hostname, route and body rather than assume a welcome page proves the application is available.
What is the difference between UFW and an EC2 security group?
UFW manages configured rules on the host. A security group applies to associated AWS resources at a network layer. Check their observed rules and the actual listener and route. A private loopback test does not need a public ingress rule.
Check your understanding
1. A valid file is saved in sites-available and no include path selects it. What do you check next?
A. Whether the intended enabled link and include pattern select that file
B. The size of a different site's page
C. Whether every resource uses the same file extension
Answer and reasoning
A. A candidate must participate in the configuration before the worker can apply its settings.
2. The online unit is active but disabled. What is established?
A. It must have no listening socket.
B. It is active now, and the separate unit enablement state is disabled.
C. Its configuration file must be absent.
Answer and reasoning
B. Those are different properties. Verify an expected listener and response to complete the check.
3. The config validates. Which result proves the named pickup site answered?
A. The release file says Ubuntu.
B. A symbolic link exists.
C. The same local request with the intended host gets the pickup marker.
Answer and reasoning
C. That observation confirms the selected response for the intended name. The other facts describe earlier layers.
4. What is needed for a curl request to the isolated listener?
A. Run on the same host with the chosen loopback port.
B. Open public SSH on every network.
C. Register the fictional example name.
Answer and reasoning
A. The socket is local and the lab explicitly supplies the HTTP hostname. Public DNS and ingress rules are unnecessary for it.
5. Which action belongs to the approved Apache site workflow on Ubuntu?
A. Edit another site's root as a diagnostic.
B. Enable the exact intended site, validate its configuration and apply it through the owned service procedure.
C. Reinstall both web servers whenever an enabled link changes.
Answer and reasoning
B. Scope the site change, verify the selected configuration and confirm the expected response after applying it.
Revision cards
Identify Ubuntu's actual result
Check the release, installed package and manager state. Package installation and unit startup are distinct observations.
Trace the enabled link
Read the include pattern and the actual link target. A file in the available directory can be outside the selected configuration.
Apply the verified candidate
A new link changes the inputs on disk. Validate the intended set and apply it through the correct process before checking the response.
Name the site you are testing
Use the intended hostname and listener. A default site can answer with a successful status and a different page.
Firewall and listener scope
Keep host rules, cloud rules and process binding separate. A loopback preview has a local client path.
Clean the owned instance
Use the same independent configuration and PID for quit. Confirm it ended before removing its named sample files.
Official references
- Ubuntu Server Nginx installation
- Ubuntu Server Apache installation and included directories
- Ubuntu 22.04 Nginx package version
- Ubuntu 22.04 Nginx common package contents
- Ubuntu 24.04 Nginx common package contents
- Ubuntu Apache module configuration helper
- Ubuntu Apache site enablement helper
- Systemd service state and enablement
- Ubuntu host firewall and UFW
- AWS security group rules
- Nginx isolated configuration and command options
- Nginx configuration reload and graceful shutdown
- Nginx server name and default selection