Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.10 Combination 5 — CentOS Stream 9 + Nginx
On CentOS Stream 9, verify the package, service and config paths on your assigned guest. Check which SELinux type its public files should have and inspect firewalld only if the guest uses it. These observations help distinguish content access from incoming network traffic.
CentOS Stream 9 वर सरावाच्या guest मधले package, service आणि config path तपासा. Public files साठी अपेक्षित SELinux type बघा. Guest वर firewalld चालू असेल तर त्याची स्थिती तपासा. File access आणि network access वेगळे तपासता येतात.
CentOS Stream 9 के अभ्यास वाले guest में package, service और config path जाँचो। सार्वजनिक files के लिए सही SELinux type देखो। Guest पर firewalld चल रहा हो तो उसकी स्थिति जाँचो। File access और network access अलग-अलग परख सकते हो।
Start with the assigned guest's package, socket and SELinux mode. The expanded exercise below shows the scoped site and label configuration, followed by actual HTTP checks.
cat /etc/os-release
sudo dnf info nginx
sudo ss -ltnp 'sport = :80'
getenforce
systemctl is-active firewalld
SELinux and custom folders
/var/www/... automatically gets the correct label, but a folder elsewhere (e.g. /data/site or /home/ec2-user/site) does not. For such folders add a rule, then relabel:
sudo semanage fcontext -a -t httpd_sys_content_t "/data/site(/.*)?" and sudo restorecon -Rv /data/site (the semanage command comes from package policycoreutils-python-utils). Files moved with mv keep their old label — always run restorecon after moving.
Ravindra Bagale's Tip
Keep SELinux in its assigned mode. A 403 has several possible causes. Compare the actual label with ls -Z and the expected label with matchpathcon, then check a relevant denial record. If the approved path already has the right policy mapping, preview and apply restorecon to that path only.
Ravindra Bagale's Tip – मराठी
SELinux चा ठरलेला mode तसाच ठेवा. 403 ची वेगवेगळी कारणे असतात. ls -Z ने actual label आणि matchpathcon ने expected label पहा. संबंधित denial record तपासा. योग्य mapping आधीच असेल तर मंजूर path वरच restorecon चा परिणाम आधी तपासा आणि मग लागू करा.
Ravindra Bagale's Tip – हिंदी
SELinux का तय mode रहने दो। 403 के कई कारण हो सकते हैं। ls -Z से actual label और matchpathcon से expected label देखो। संबंधित denial record जाँचो। सही mapping पहले से है तो केवल मंजूर path पर restorecon का असर पहले जाँचो और फिर लागू करो।
Lab
Chala, khalcha CentOS Stream 9 lab kara. getenforce ne sadhyacha mode paha. ls -Z ani matchpathcon ne saravachya file cha actual ani expected label tapaasa. Assigned hostname ne local HTTP request kara ani status, content ani log nondva.
Host a market timetable on CentOS Stream 9 with Nginx
A municipal market publishes an HTML timetable for vendors. A trainee transfers the approved files to a dedicated CentOS Stream 9 guest, writes a new Nginx block, and checks that the worker listens. The homepage responds, but the separately uploaded timetable yields 403. A second test from a classroom computer cannot connect at all. Those failures give us different evidence. The 403 is an HTTP response made after a request arrived. The failed connection may have stopped before Nginx saw that request. Fixing both requires identifying where each path ended.
We will build a small static vhost, identify who can read its public files through both ordinary Linux permissions and SELinux, and read the host firewall's active state without opening an unnecessary network path. SELinux is the policy layer that can allow or refuse an operation based on the context of a process and the context of a resource. Firewalld is a separate host network controls manager. One helps decide whether the web worker can open a file, and the other can govern whether a remote connection reaches the listener.
Use the commands on an assigned disposable CentOS Stream 9 system. An offline evidence exercise later uses synthetic records so you can work through the same reasoning without a CentOS host. Keep the web release limited to ordinary sample pages. There is no need to open both HTTP and HTTPS, change global trust settings or turn off a policy layer just to prove a local practice site.
Inventory the operating system, package and listening service
CentOS Stream tracks development immediately ahead of the corresponding Red Hat Enterprise Linux release. The systems share familiar package and policy conventions, while the exact package version, configuration and initial state still depend on the installed guest. Read /etc/os-release and confirm CentOS Stream with version 9. If this is an EC2 instance, record its ID and approved network path rather than inferring identity from a shell prompt. Check for existing socket owners before installing another managed service.
cat /etc/os-release
id
rpm -q nginx
sudo dnf info nginx
sudo ss -ltnp 'sport = :80'
systemctl is-active nginx
systemctl is-active firewalld
getenforce
Run the observations separately. An absent package or inactive service can report a non-successful exit status as expected. The package info query reports what the configured repository knows, while the RPM query asks what is already installed. The socket check reveals which process owns the listening port if one exists. If you find an existing web server and do not own its sites, use a fresh assigned guest instead of stopping it. The firewall service check and SELinux mode check describe two additional independent states worth writing down.
On the approved guest, run sudo dnf install nginx after reviewing the transaction. Use the systemd unit named nginx when the repository supplies the expected packaged setup. Read its real invocation with systemctl cat nginx before assuming the location of its inputs. Use nginx -v and rpm -q nginx to capture installed versions. These records are diagnostic context and do not establish that the practice server config is loaded or that the intended listener is available.
sudo dnf install nginx
nginx -v
systemctl cat nginx
sudo nginx -T
systemctl is-enabled nginx
Find the main HTTP context and whether it includes files matching /etc/nginx/conf.d/*.conf. This convention is common in RPM layouts. The actual nginx -T output and service command are better evidence than the directory alone. A candidate file needs to appear under a loaded include, and its contents need to fit that location. Check the existing port 80 blocks, MIME type mappings and runtime user. Advertising your practice name does not require a different site to lose its own default listener or root.
Compare the planned file path with the labels on disk
For this sample use /srv/market-timetable-lab as an approved fresh publish directory. It deliberately sits outside the most familiar web root so you have to ask what the system expects there. Put index.html, timetable.html, 404.html and css/market.css beneath it. Use the homepage marker “Market collection desk”, the timetable marker “Saturday vendor timetable”, the error text “Market listing unavailable” and a stylesheet class called .vendor-slot. Build the release from these exact files. Keep intermediate notes and hidden files elsewhere.
Linux modes and ownership determine whether the worker's user or groups can traverse directories and read each file. Directory execute permission means permission to traverse the path in this context. A web file can be ordinarily world-readable while a parent directory denies traversal. If the worker can get through the permissions check, SELinux can still enforce a separate policy decision. Use namei -l for the path and ls -Z for SELinux contexts. The file's media type in HTTP has nothing to do with its SELinux label.
ROOT=/srv/market-timetable-lab
namei -l "$ROOT/timetable.html"
ls -Zd "$ROOT" "$ROOT/css" "$ROOT/timetable.html"
matchpathcon "$ROOT/timetable.html"
ps -eZ | grep '[n]ginx'
getenforce
The ls -Z output shows the actual file context. matchpathcon asks which context should apply to a path under the installed rules. The process display reports the context of an Nginx process if it is already running. A typical targeted configuration uses a context field such as httpd_t for a web process and httpd_sys_content_t for ordinary readable public web content. Read what the guest actually reports because its policy and runtime process can differ from the expected package. The important comparison is the process, file path, expected and actual file types, and operation in question.
In enforcing mode the loaded policy controls whether an operation proceeds. Permissive mode usually records violations without enforcing them for processes in its scope, and a disabled status means SELinux is not applying its normal policy. Read the mode. Keep the exercise in its assigned security state. If a scoped directory has the wrong content type, correct how that directory is labelled. The inputs to a specific decision are far more useful than weakening the policy for every process on the machine.
Choose the correct mapping before changing the label
A path mapping describes what context files at matching paths should have. The current label is stored as part of the actual file's attributes. restorecon applies labels selected from the active file-context rules. It does not automatically classify everything Nginx opens as public content. For a path already covered by the expected web rules, a scoped restore can return a misplaced file to its defined type. For a new root outside that scope, inspect the expected type first. If the mapping is wrong for the approved public use, the administrator needs to add the appropriate scoped rule.
Run sudo semanage fcontext -l -C to inspect existing local customizations where the utility is installed. The package policycoreutils-python-utils supplies the management tools on the expected CentOS Stream family image. Get the package through the approved repository if needed. Verify that none of the existing rules already expresses the intended type and that the sample path is yours. If the current mapping already gives the intended web type, skip adding a new rule. If an existing site or policy overlaps, ask its owner to decide how to handle it.
sudo semanage fcontext -l -C
matchpathcon /srv/market-timetable-lab/timetable.html
# Only for the new dedicated lab root after policy review.
sudo semanage fcontext -a -t httpd_sys_content_t '/srv/market-timetable-lab(/.*)?'
sudo restorecon -nRv /srv/market-timetable-lab
sudo restorecon -Rv /srv/market-timetable-lab
matchpathcon -V /srv/market-timetable-lab/timetable.html
ls -Zd /srv/market-timetable-lab /srv/market-timetable-lab/timetable.html
Quote the pattern so the shell passes it unchanged. The expression selects the site root and its descendants, rather than every directory under /srv. The preview option -n reports prospective changes without applying them. Read the listing and confirm that its scope is the approved sample. The apply run then updates the labels from the rule. matchpathcon -V checks whether the existing label matches what policy expects. Capture the verification before and after for the particular file that gave a denial. A matching label still leaves other filesystem and server authorization checks in effect.
Do not add a write-oriented content type when the worker only sends static bytes. Keep the release publisher's permissions separate from the worker's ability to read it. The same rule should let you check a later upload under this root. A newly copied or moved file can have attributes that depend on the operation, so inspect it directly. A one-off label change without a matching policy rule can disappear when a later restore applies the expected path context. Record the rule as part of the site setup for any maintainer who repeats the release.
Validate the market's named site before activation
Use a new candidate named market-timetable-lab.conf and the practice name market-lookup.example.test. This sample expresses the named site on the already approved IPv4 HTTP port. It leaves other definitions and their defaults intact. Use a synthetic host override in the check because .test is for testing. A service that reports an outbound IP address cannot tell you which address belongs to the approved inbound endpoint of this guest.
server {
listen 80;
server_name market-lookup.example.test;
root /srv/market-timetable-lab;
index index.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
access_log /var/log/nginx/market-timetable-lab.access.log;
error_log /var/log/nginx/market-timetable-lab.error.log;
}
The root tells Nginx where to read the files for the selected name. It does not change labels at that path. The sample pages consist of ordinary HTML and CSS files and need no network access from Nginx to another backend. The local error page must have the same readable path and labels as the rest of the published content. The access log shows which named site handled an accepted request, and the error log can give context for unsuccessful reads. Check logs against their own approved file permissions and internal retention rules.
(
set -eu
candidate="$PWD/market-timetable-lab.conf"
target=/etc/nginx/conf.d/market-timetable-lab.conf
test -f "$candidate"
test ! -L "$candidate"
sudo sh -c '
set -euC
test ! -e "$2"
test ! -L "$2"
umask 022
cat "$1" > "$2"
' sh "$candidate" "$target"
sudo nginx -t
)
Run the fresh-only helper after confirming the active include path and exact candidate content. Review admin ownership and coordinate with the lab owner so there is no concurrent edit. A destination collision calls for investigation, because a similar folder or name may belong to another learner. If the new configuration fails to validate, correct or remove only this new file and test again. Apply with sudo systemctl reload nginx on the approved running service, or sudo systemctl start nginx if it is inactive. Run systemctl is-active nginx and inspect the socket before assuming the HTTP check will work.
Lab one. Verify the complete local market site
Prerequisites are the assigned CentOS Stream 9 guest, a reviewed configuration and enabled HTTP service, the appropriately labelled public directory, and the four marked files. Use a local connection inside the guest. The curl address override maps just one name and port to 127.0.0.1. The browser-style request still names the market. That check exercises the vhost and its file reads without relying on a routable public address or an open inbound firewall rule.
(
set -eu
name=market-lookup.example.test
body=$(mktemp "${TMPDIR:-/tmp}/market-http.XXXXXX")
trap 'rm -f -- "$body"' EXIT
fetch() {
curl --noproxy '*' --resolve "$name:80:127.0.0.1" \
--silent --show-error --max-time 5 --output "$body" \
--write-out "$1 %{http_code} %{content_type}\n" "http://$name$1"
}
fetch /
grep -F 'Market collection desk' "$body"
fetch /timetable.html
grep -F 'Saturday vendor timetable' "$body"
fetch /css/market.css
grep -F '.vendor-slot' "$body"
fetch /closed-stall
grep -F 'Market listing unavailable' "$body"
)
Read the four printed statuses alongside the content. The homepage and timetable should give 200 and HTML, and the stylesheet should give 200 and a CSS media type. The closed stall is deliberately absent and should return the error body and status 404. If a marker check stops the script, inspect that request directly so you can see its response status, body and selected listener. A missing stylesheet and unreadable timetable can both be framed as “site broken” in a help request, but they belong to separate URL checks.
sudo tail -n 15 /var/log/nginx/market-timetable-lab.access.log
sudo tail -n 15 /var/log/nginx/market-timetable-lab.error.log
sudo journalctl -u nginx --no-pager -n 18
A current per-site log entry confirms that Nginx handled that HTTP exchange for this site. If an access record exists with a permission symptom, read the error log and check the exact path. If no HTTP exchange happened, the systemd journal and socket checks precede file permissions. The exercise replaces only a single response buffer for each check and removes that temporary file at the end. Make a note of the successful final result so you can compare it after any later firewall test.
Read a recorded denial in context
An AVC is an Access Vector Cache record in the SELinux audit trail. A message about a denied operation can help explain a request made by a confined web worker. Start with the corrected test name, path and approximate time. Root system logs can contain many unrelated records. Run a search with only the required time and message types on the training guest. If there is a relevant entry, check the associated event ID, executable or process name, operation and source and target context fields. If the audit service or command is unavailable, consult the host's configured logging path and owner.
sudo ausearch -m AVC,USER_AVC -ts recent -i
For example, a synthetic record might describe comm="nginx" attempting to read timetable.html. A source context with web worker type httpd_t, a target file type different from the expected content type, and a denied open or read operation all point toward the labelled-file part of the request. Compare the actual and expected labels before choosing a repair. A denial for a different process or unrelated path cannot explain the market response solely because it happened in the same minute.
A missing AVC line by itself does not establish that policy permitted every operation. The deployment can have different audit configuration, the query may omit the relevant time, and the request may have failed earlier. Read server and OS evidence together. If Nginx never reached the file because it selected a different vhost or directory policy, there may be nothing meaningful to find in the expected file's audit records. Conversely, a relevant denial might report checking a parent directory instead of reading the last filename. A path walk and a repeated scoped request make the relationship easier to see.
Work toward the smallest supported repair. If the file did not acquire the intended label from an existing rule, preview and apply restorecon only to the approved release or affected path and recheck. If the existing mapping is unsuitable for the planned public root, take the mapping route described earlier. If ordinary directory traversal is the issue, a label change cannot repair that access check. After applying one fix, repeat the same exact request. More than one issue may exist, so write down which observation changed instead of declaring success after the first command.
Read the host firewall path before asking for a rule
Firewalld organizes rules into zones, which attach a security policy to interfaces or source networks. The default zone is only the zone chosen when a more specific assignment does not apply. A cloud guest may have several interfaces and explicit zone bindings. Ask which interface and permitted client source will carry the HTTP connection. The effective inbound rules depend on that association and any other relevant firewall policy. Query the appropriate zone and use its actual service and port configuration rather than applying a command aimed at an unspecified default.
sudo firewall-cmd --state
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --get-default-zone
ip -brief address
ZONE='REPLACE_WITH_APPROVED_INGRESS_ZONE'
sudo firewall-cmd --zone="$ZONE" --list-all
sudo firewall-cmd --permanent --zone="$ZONE" --list-all
sudo firewall-cmd --info-service=http
Run the firewalld queries when the guest actually uses an active firewalld daemon. The runtime view governs its current rules. The permanent view supplies saved settings for later activation, including what a reload can read. A permanent listing can therefore show a rule that is not effective yet. A temporary runtime rule can serve a bounded exercise and disappear after a reload or its configured timeout, depending on how it was created. A named service describes defined ports and protocols. Review its actual definition rather than treating the label http as a command that starts Nginx.
This exercise needs only HTTP over the allowed path. Verify loopback first. A remote learner test should happen only when the trainer already provided permitted connectivity or approves a narrowly scoped test rule. A whole-zone service change applies according to the scope of that zone. If only one student client needs to connect, the owner can choose a source-limited and timed runtime rule where appropriate, and should record its exact removal or expiry. Do not open HTTPS merely because the enabled site has HTML pages. That would authorize a port the sample has no TLS configuration to serve.
Guest firewall and EC2 security groups are separate control points. An available guest socket and a permitted local request say nothing about whether a remote route or security group will deliver this client's connection. For an external lab verify the approved instance address, the applicable EC2 route and allowed client, any network ACL involved, and the guest listener. A private network path can be valid without an internet gateway or public address. Identify the intended delivery route before making an access report.
For an approved direct remote test distinguish the address chosen for the connection from the host inside the URL. Where the assigned domain is a testing name, curl --resolve maps it for one destination and one port. If normal DNS is part of the assignment, verify that separately with an ordinary request using the actual assigned DNS name. A failed client path with no accepted request is a reason to check address, port, routing and filtering. A client path with a market 403 has already reached the HTTP service and needs the file or policy investigation appropriate to its own log evidence.
Lab two. Choose the next observation from sample records
For this lab you need Python 3 and no administrative access. The observations below are synthetic summaries, including the selected vhost, named response and policy evidence where available. Read them and predict which layer each case should investigate first. The scripted cases are deliberately simple. A real guest might require multiple follow-up checks, and these records make no changes to any firewall or operating system policy.
python3 - <<'PY'
cases = [
{"case": "timetable", "local_status": 403, "same_site": True,
"matching_avc": True, "remote_timeout": False},
{"case": "classroom client", "local_status": 200, "same_site": True,
"matching_avc": False, "remote_timeout": True},
{"case": "welcome page", "local_status": 200, "same_site": False,
"matching_avc": False, "remote_timeout": False},
{"case": "missing sheet", "local_status": 404, "same_site": True,
"matching_avc": False, "remote_timeout": False},
]
expected = ["Label and file access", "Delivery path", "Name selection",
"File path and release manifest"]
for record, answer in zip(cases, expected):
if record["remote_timeout"] and record["local_status"] == 200:
layer = "Delivery path"
elif not record["same_site"]:
layer = "Name selection"
elif record["local_status"] == 403 and record["matching_avc"]:
layer = "Label and file access"
elif record["local_status"] == 404:
layer = "File path and release manifest"
else:
layer = "Collect more evidence"
assert layer == answer
print(f'{record["case"]}: {layer}')
PY
The timetable points toward labels because there is a matching denial record after host and file checks. The classroom client calls for the delivery path because the same expected local page succeeds. The welcome page points to name selection, and the missing sheet calls for comparison of the URL with the release manifest. A 404 is meaningful only in context: we already know it happened within the intended host for the synthetic case. For the real lab reject reasoning that begins from a status alone and keep the corresponding request and file evidence.
Practise changing one observation at a time. If the timetable's matching AVC disappears, the example loses the evidence that led directly to label investigation, and you need the error log and path. If the classroom client starts receiving the expected content after an approved scoped rule, record the exact test and current rule state. The offline program ends without creating files or contacting a network. Cleanup for a real exercise is a separate task involving its defined site, approved rule and release directory.
Explain a concrete before-and-after label repair
Consider a supervised fixture where timetable.html has ordinary file mode 0644 and namei -l shows all required parents are traversable by the web worker. The homepage and stylesheet both return the right body. The named request for the timetable produces an access error and the audit event describes the relevant Nginx process opening that file. This pattern gives several independent facts. The listener and site selection work, the read issue is specific to the new file, and the refusal came from a file access check. First record these facts before changing a label.
Suppose the type shown under ls -Z for that file is a home-directory type, while matchpathcon expects httpd_sys_content_t at the published path. This means the current attribute differs from the intended mapping. Have the approved administrator preview restorecon -nv /srv/market-timetable-lab/timetable.html. If its reported change makes sense, apply the scoped restore and verify the label. The command can leave everything alone if the attribute already matches. Your observation after the operation should reflect the expected type and an HTTP request to the same path.
Record the log event before and the same authorized request afterward. A correctly prepared new file can then produce 200, the HTML media type and the timetable marker. Do not expect a single status for every kind of unreadable path. Nginx may fail at checking a candidate, mapping a directory or opening a file, and chosen rules can change how it reports the failure. If your status differs, use the actual error log and matching audit evidence to see what occurred. This diagnostic sequence has an intended decision, not a required initial 403 for every machine.
Now consider a slightly different fixture. The release originally was placed below a default root, but the latest change points into a new /srv directory. Both the current and expected label for the timetable are something other than the web content type. That is a mapping issue rather than stale file attributes. Inspect the new root's scope and, if approved, add the site-specific file context rule before running the preview and restore. The two scenarios can look identical in a browser, but the actual and expected types explain why they need different administration steps.
Compare three observations across the network path
Some students describe a host firewall as though it controlled the page contents. In this exercise check which path was taken. The local request is sent from inside the guest to its own listener. A client in another network sends packets through route and traffic controls before Nginx can parse the request. When that external client reaches the expected named site, the server's file-opening rules can run. The delivery and read decisions are in sequence. You can prove one processed correctly without proving the others.
| Local named request | Permitted external client | Next piece of evidence |
|---|---|---|
| Connection fails and no listener appears | Either path may fail | Read the service journal and effective port binding. |
| 200 with expected timetable and CSS | Times out at the approved address | Identify route, destination, interface zone and security group scope. |
| 200 from the wrong site | Not attempted | Send the correct hostname to the eligible listener and inspect its definition. |
| 403 in the market access log | Same refusal from the approved host | Compare the mapped file, ordinary permissions and a relevant SELinux event. |
| 404 with the custom body for a removed stall | Same status and body for that URL | Compare the results with the intentionally absent path in the plan. |
Save target address and scheme for both tests. A browser may attempt HTTPS or prefer an IPv6 address while your local curl used IPv4 and HTTP. If these requests do not describe the same delivery service, fix the comparison before treating the results as a contradiction. A real TLS endpoint also needs its own listener and certificate and should be checked separately. For the market exercise keep the HTTP and local host mapping explicit. Use a remote path only after confirming the approved port and address.
Read the active rules and plan an intentionally temporary change
Suppose an inspection prints a zone with one interface and another zone with a source range. The test traffic's path determines which controls are relevant. Ask which source range the instructor assigned and how that range enters the guest. Use the active zone and policy output to understand current behaviour. An administrator can choose a narrower runtime exception and set a timeout when the lab calls for remote HTTP, but the exception's correct location depends on those assignments. A rule targeting an irrelevant zone may appear in command output and have no effect on the test.
Compare the host filter with the EC2 rules before introducing a change. A learner on the campus network could be permitted by the security group and blocked by the guest. Another learner could be blocked by the security group before reaching a guest rule that would otherwise permit them. Check the actual source presented to the cloud and guest as assigned, since upstream routing or proxies may change what appears on one side. Record the client's allowed test path and observe whether the request reaches the correct service. Avoid recording private addresses from unrelated users.
If the trainer needs the exception only during an exercise, keep it temporary and document the name or exact rule text. Firewalld's runtime view can change during the session. Its saved configuration and current rules can both be meaningful, and they need an explicit reason to become identical. An unconditional reload can replace unrelated temporary rules. Read current and permanent states and preserve the existing arrangement. Cleanup can remove the one adopted test rule or verify its expiry, depending on the approved procedure.
Verify a second timetable release with the same policy
Imagine the first timetable lists a morning stall collection time and the second moves it to the afternoon. For the second release, preserve the approved first copy outside the served tree. Stage the new file and decide whether the configuration will keep the existing root or intentionally select a different root. The path mapping is part of a new root's preparation. If it lives elsewhere under /srv, the first root's SELinux rule might not apply to it. Confirm each file and ancestor under the new configuration, then validate and activate the Nginx change in the normal order.
When publishing into the existing approved root, check how the copy was created and compare its attributes to the expected policy. A publisher might preserve source attributes, overwrite existing bytes or create a new inode, depending on the method. Observe the result rather than treating all copy commands as equivalent. Compare the timetable text and the stylesheet marker through the same named request, and keep the genuine 404 behaviour for a closed stall. A visible change on the homepage cannot prove the independent timetable switched to the intended bytes.
Record the retry so the next maintainer can reproduce it. Include the scope, exact URL, listener, path contexts, and release marker. A note that says “permissions fixed” loses the distinction between ordinary filesystem access and label policy. A note that lists an entire audit log buries the specific file event. Keep one concise record for the resource that failed and another for any remote path problem. That separates the follow-up evidence and the different personnel who may own each change.
Choose evidence for a publisher's checklist
Give the timetable publisher a small checklist containing the planned public file paths and the location where they should land. The publisher can compare the two versions and tell which one is ready. A privileged administrator can separately verify how the worker reads them under policy. Keep those roles separate so the publisher never has to grant general write access to the running service. For a routine public-file release the new asset needs a predictable ordinary mode and the expected label at its destination.
When you receive an archive, inspect what it contains before extracting into a staging directory created for the lesson. A filesystem restore that preserves old attributes can recreate a mismatch even when the filenames look correct. Check the label from the actual published path after transfer, because a local archive listing cannot read the remote policy's expected type. Inspect the filename and directory case too. A label that matches its declared mapping cannot put a file at a URL containing a different letter or directory name. Run the exact expected publication requests after staging.
For routine change review, compare the served CSS marker and timetable status as well as the homepage. Retain the marked acceptance output with the intended release date. If someone asks why you kept the host's policy intact, cite the specific test path and evidence you used. The market exercise succeeds because root selection, ordinary access and policy line up for the file we intentionally published. A clean acceptance check also lets you attach any remaining external access issue to a separate route and client rather than reopening filesystem changes that already worked.
Remove the exercise state without changing protected services
Restore the original configuration by removing the unique candidate from the active include set if you own it and the exercise is finished. Verify that the remaining configuration passes nginx -t and safely reload or stop the service according to the lab plan. Check that the market block is absent and any intended default behaves as it did before. Then remove the synthetic release if it is no longer in use. Use its exact approved root name and keep other sites and shared logs under their owner's control.
If you added the narrowly scoped context mapping for this exercise and the owner approves its removal, remove that exact mapping with sudo semanage fcontext -d '/srv/market-timetable-lab(/.*)?'. This changes which context is expected for matching paths. It does not automatically relabel existing objects. If the root remains and has an agreed different purpose, inspect the new expectation and apply a scoped restore under that purpose. Preserve pre-existing mappings. Only remove an approved firewall exception you created, and check its current runtime state or expiry.
Return the boot and service state to the intended setting separately. Removing one site's configuration is not a reason to uninstall a shared Nginx package. For an isolated EC2 exercise, use the trainer's resource list to handle the instance, volume and any allocated address. Keep the lesson outcome outside the disposable guest if it needs to be reviewed. No cloud cleanup is needed for the offline decision exercise, which makes only in-memory records.
Interview questions with explained answers
Why can a file with mode 0644 still be unavailable to a CentOS web server?
The server also needs permission to traverse each parent directory and authorization to read the selected path. SELinux can enforce a separate decision based on process and file contexts and the operation. Check the actual worker, path attributes and matching log evidence.
What is different about matchpathcon and restorecon?
The first reports or verifies the expected context under the current mapping. The second can apply that expectation to the file. If the rule does not name an appropriate type for a new approved web root, fix the scoped mapping before expecting a restore to change that result.
How would you separate an inbound connectivity issue from an SELinux concern?
Use the exact intended host and path in local and approved remote checks. If local content succeeds and the remote client cannot connect, inspect its delivery path. If the named request arrives and logs a denial with matching audit evidence, inspect the labelled operation and filesystem context.
Why read both runtime and permanent firewalld settings?
Runtime rules affect current traffic. Permanent rules are saved for later application. A temporary test can be present in only one set, so comparing them helps explain current results and plan cleanup.
Which evidence would justify a controlled configuration reload?
Identify the approved candidate, confirm the actual include, resolve any name or port conflicts, and obtain a clean syntax test. Then use the managed process's reload procedure and request the named site to verify its accepted configuration.
Check your understanding
The file mode looks right, but the actual context differs from the expected web type. Which scoped tool can apply the expected label?
Show answer
restoreconapplies the path's expected context. Preview only the affected approved path and verify the result after applying it.Both the actual and expected types are unsuitable for the approved new public root. Will repeatedly running restorecon select a different type?
Show answer
It will keep applying the installed mapping. Have the administrator review and add a narrowly scoped path rule for the approved web use, then restore and check.
The local market URL and CSS work but the classroom client times out. Where would you start?
Show answer
Confirm the remote client's intended address and port, actual listener, route and applicable network rules. The local response shows the server could read those resources along the local path.
A host already has a named site on port 80. Can Nginx host the market site alongside it?
Show answer
One Nginx listener can dispatch by name among eligible server blocks. Add only an approved distinct name and root and confirm the existing site and default behaviour after activation.
Why is opening the HTTPS service unnecessary for this exercise?
Show answer
It uses a local HTTP listener on port 80. A separate HTTPS exercise would first need a justified endpoint, a matching listener and validated certificate and policy.
Practice the diagnosis and handoff
Write a four-column record for one observed file: current label, expected label, effective worker context and exact requested URL. Explain which two fields matter to a scoped label repair.
In the offline exercise change the timetable's matching AVC flag and adjust the expected outcome. Explain which server and file observations you would ask for before changing policy.
Make two separate acceptance records for loopback and a permitted remote path. Label the source, destination, named vhost and response. Document whether a firewall change was required and how its cleanup would be verified.
Revision cards
- Ordinary file access
- Check the worker's identity, file read permission and directory traversal before concluding that a label caused a denial.
- SELinux type
- One part of the process and file context used by the installed authorization policy.
- Expected mapping
- The file context policy selects a label for a path. Compare with the real file context to distinguish the two failure types.
- Scoped restore
- Preview and apply an approved context mapping to the affected release location only.
- Firewalld active zone
- A runtime scope assigned to traffic through interfaces or sources. Inspect the relevant zone before deciding how to reach the test.
- Nginx site evidence
- A valid config, correct host and port, and intended status, marker and log together show what the service did.
Official sources
- CentOS Stream project overview
- RHEL 9 Nginx site and content context examples
- SELinux modes and contexts
- SELinux file context mapping
- SELinux audit interpretation
- restorecon preview and apply options
- matchpathcon context checking
- Firewalld zones and current or saved rules
- Scoped firewalld rule syntax
- Nginx host and path selection
- Nginx file and error mapping
- Nginx configuration activation
- VPC security groups
- Curl local destination override
- Reserved testing names