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

Chapter 8: Configuring Nginx and Apache

AWS Cloud

Interview Questions

Use these Nginx and Apache scenarios to practice explaining the directive, the affected request and the result you would verify.

Q1. What is a server block in Nginx and a virtual host in Apache?
A site configuration for eligible connections and names. It can define content, handlers and logs. Multiple definitions can share one listener, and Apache opens the listener with a separate Listen directive.
Q2. How does Nginx decide which server block handles a request?
Nginx identifies the local address and port. For ordinary HTTP host matching it looks for an exact name, supported wildcard forms and the first matching regex. An unmatched name uses the explicit default for that listener or its first defined server.
Q3. You changed the DocumentRoot and now get 403 Forbidden. What do you check?
Trace the selected site, mapped path, index behavior and precise error. Check the effective Apache authorization, worker traversal and read permission, and any applicable enforcing host policy before making a targeted correction.
Q4. How do you run Apache on port 8081?
Choose an intended unused address and port. For a private example use Listen 127.0.0.1:8081 and the matching <VirtualHost 127.0.0.1:8081>. Validate the candidate, use the approved apply workflow and verify the socket and actual request. Inspect network and host policy only for the relevant access design and failure.
Q5. What is the difference between reload and restart?
A supported reload requests application of updated configuration. Nginx can keep its previously accepted configuration if the candidate fails to apply. A full restart has different connection and availability effects. Confirm the deployment’s service operation and verify actual responses.
Q6. How do you inspect Apache’s candidate virtual hosts?
Use the appropriate Apache wrapper with -S and the settings the service uses. Nginx’s -T tests and prints files read by that invocation. Check activation and HTTP behavior separately.
Q7. How do you redirect www.example.com to example.com?
Use a separate alternate-name policy with a known canonical destination, such as Nginx return 301 https://example.com$request_uri;. Check the initial status and Location, then the destination and TLS behavior.

More questions across stacks

Q. How do you proxy a Spring Boot app with nginx?
Use a scoped proxy_pass to the application’s verified HTTP endpoint. Test path mapping and forwarded authority. Configure trust for forwarded metadata at the relevant proxy and application boundaries.

Q. How does nginx talk to PHP-FPM?
Use FastCGI with the actual FPM socket or endpoint. Check the effective parameters, including the script filename mapping required by the pool, and verify it executes an approved test script.

Q. How do you serve a React or Angular app?
Choose the deployment supported by the application’s rendering model. A client-routed static build can fall back to its shell for selected routes. Keep missing assets and APIs distinct; SSR or hybrid routes need the correct runtime or generated artifacts.

Q. How do you rate-limit a login URL in nginx?
Define the key and rate with limit_req_zone under HTTP and apply limit_req in the intended scope. Verify effective trust for the key, delay, burst and response policy on a disposable fixture.

Q. What is the Apache equivalent of nginx's proxy_pass?
Use scoped ProxyPass with the HTTP proxy module and actual backend. Consider ProxyPassReverse for backend redirect headers and test the matched paths. Avoid enabling an open forward proxy.

Q. Where do you terminate TLS on AWS?
Terminate the client TLS connection at the intended server or an Application Load Balancer HTTPS listener. The ALB’s own certificate credentials can stay at the load balancer. Configure the target leg independently for its intended HTTP or HTTPS policy.

Q. How do you redirect HTTP to HTTPS in nginx?
Use a known HTTPS destination on the intended HTTP site, such as return 301 https://example.com$request_uri;. Verify the target and certificate rather than using an arbitrary request host.

Q. How do you add security headers in nginx?
Set the intended header, for example add_header X-Content-Type-Options nosniff always; where appropriate. Check inheritance, status and proxy behavior for actual success and error GET requests.

Q. How do you hide the PHP version?
expose_php = Off in php.ini.

Q. What is the Tomcat equivalent of server_tokens?
Tomcat Connector settings can override a Server header or remove values set by the application, depending on the options and installed version. Review applications and generated error pages separately.

Key terms

  • server_name: The host names a server block answers to.
  • listen: The port (and IP) a block binds to.
  • default_server marks the fallback for a particular Nginx listen address and port.
  • Options -Indexes: The Apache setting that turns off directory listing.
  • semanage fcontext manages persistent path-to-context rules. Applying the labels is separate.
  • limit_req: nginx request rate limiting.

Mini case study

Suppose we are a junior cloud engineer at a Bengaluru e-commerce startup (sample data). The team runs a PHP admin, a Node.js storefront API and a Python report job on two EC2 instances. Using this chapter, you write a one-page runbook: which service listens where, how to test and reload each one, which logs to read, and which interfaces and ports need public, private or approved operator access. New team members can then fix most problems on their own.

Answer from a specific request and observable result

In a configuration interview, name the exact input that matters before listing commands. A complete answer usually states which stage provides the decision, proposes a small controlled comparison, and explains how to interpret both outcomes. For example, a request to a bare IP that returns a welcome page does not by itself establish a configuration failure. Hold the address and path fixed, send the expected hostname, and compare the status, selected site and body. That answer gives the interviewer an observable distinction rather than a memorized directive.

For each question below, answer aloud before opening the explanation. Try to give a short answer you could deliver at a terminal, then read the reasoning and add the operational details you missed. You can point to the demonstrated lesson for deeper evidence. Most questions deliberately include two plausible causes. Your job is to identify what you know from the premise and propose the next useful check. If a piece of evidence depends on a particular package or network environment, name that boundary instead of making it a universal rule.

Listener, name and certificate questions

Two websites share the same EC2 address. How can both respond on the same port?

The shared listener accepts connections at the address and port. An Nginx server block or Apache virtual host defines behavior for eligible requests on that endpoint. The HTTP authority selects a known site name there, and each site's routes can have different data, logs and application handlers. A header called Host commonly carries the authority in HTTP/1.1. The earlier TLS handshake for HTTPS may use a server-name extension to choose a certificate before any HTTP headers arrive. Port choices and site names have separate jobs.

Give a worked contrast. A request to library.test and a request to workshop.test can connect to the same network address on the same port and ask for /index.html. If the first returns a continuing library marker and the second returns workshop, the result matches independent routing on a shared endpoint. If both return the same generic page, inspect naming and defaults before concluding they share a root. Use a per-request connection override so you have controlled where the two requests arrived. The different bodies are stronger evidence than both showing 200.

How do Nginx and Apache choose the fallback when the expected name is missing?

Start with which address and port accepted the connection. Nginx can mark the default for that combination on the listen directive. If there is no explicit option, check the first eligible definition. The server_name value an operator uses as a convention is not the default selector. Exact names can take precedence over wildcard and regular expression names. A broad match could select a configured site rather than falling back. Inspect the names actually applicable to that listener before interpreting an unknown host.

Apache also groups by the best address and port match. It considers eligible ServerName and ServerAlias entries, and the first eligible virtual host usually receives a name that does not match the group. Its position follows the parsed configuration, including what the main file explicitly reads or what wildcard includes expand. A filename named default does not independently determine precedence. Run the correct candidate report and use a control probe with the intended name and a valid unrecognized name. This makes it possible to detect when the real issue was the client's input rather than the default's existence.

An Apache site for port 8081 appears in the report, but a connection is refused. What comes next?

A VirtualHost section describes a candidate for a connection that arrives on its specified address and port. It does not open the socket. Check the intended Listen directive and the host's actual socket list with a process-aware diagnostic if permitted. Confirm the process initialized successfully. An address bound to loopback is reachable through that interface on the same machine. It cannot simply be reached from a workstation through the instance's network address because a security-group rule includes the port. Start with the correct local probe.

If the local socket exists and answers the expected hostname, then check the relevant approved remote route if the service is meant to be remote. Identify source, destination and transport. On AWS this can involve security groups, subnet controls and routes. The host firewall or a local access mechanism can be relevant. An error about address already in use asks for the observed owner and bind overlap, not permission to stop another service. The strongest answer separates checking the live socket, calling the named route and enabling any authorized remote access.

The DNS alias resolves correctly but the browser gets the wrong website. Why?

The alias helps resolve the hostname in the URL to a destination. It ordinarily does not rewrite the name the web client sends. If a browser opens courses.example.net and DNS resolves it through learning.example.net, the web request is still for courses.example.net. The latter needs a resulting site definition, explicit supported alias or intentional redirect. The fallback can otherwise answer. Compare the actual request name and destination to the virtual host group. Verify any edge that forwards a different authority to its backend.

For HTTPS, add a test of the first selected certificate. The source name needs valid TLS coverage even if its only job is to redirect. An expected redirect with no matching first certificate is unusable for normal clients. A useful interview answer offers two checks: a forced resolution to the intended service that preserves the name in the URL, and a normal public request that includes the actual DNS and edge route. They produce evidence about different boundaries. Observe the final body and the initial redirect separately when one is intended.

When would an Application Load Balancer use a certificate without putting that certificate's private key on an origin?

An AWS Application Load Balancer can use an HTTPS listener with a certificate attached at the load balancer. The client TLS session terminates at that listener. If the intended backend route uses HTTP according to its accepted network and security design, the targets do not need to carry the load balancer's particular certificate and private key. If the target connection uses HTTPS, it has its own settings and credentials. Certifying the front door does not establish the transport policy or application success on the next hop.

Diagram the two connections and label which service negotiates TLS where. Select the actual advertised hostname and certificate for the first hop. For the next hop verify listener protocol, forwarding rule, target health and the expected app response. If a certificate fails for an alternate name, confirm which infrastructure terminates the first session before changing the origin file. Conversely, a working HTTPS front door with a 502 can be a backend issue. The request and target logs should establish what the load balancer attempted and which service answered.

File mapping, access and path selection questions

Explain why a move from one Apache DocumentRoot to another can produce 403 while syntax passes.

The document root is the base path for ordinary static-file lookups. An applicable Directory section controls filesystem-specific access and options. The new mapping can be valid text and lead to a real file, yet lose a formerly applicable public grant. A broader policy may deny access at the new location. A broader allowed parent could produce a different result, so inspect the exact mapping and effective policy instead of guaranteeing 403. The worker also needs actual filesystem and host-policy access.

Outline a diagnostic sequence. Check the same named site's direct file and directory root, inspect the selected path and relevant error, then identify whether the failure is a missing index, Apache authorizer or an OS denial. Document old and new policy scopes. Update only the intended site, retain necessary restrictions, and verify both a public marker and an intentionally denied harmless marker. The Apache DocumentRoot exercise reproduces a valid root-only change that is refused, then fixes the matching Directory rule and restores the previous release.

What does an Nginx prefix location do before root or alias maps a file?

A prefix location matches an opening part of the normalized URI. It is a candidate context for request handling. It does not itself remove that prefix or identify a filesystem folder. Root lookup normally appends the URI to its configured directory. A simple alias in a prefix location can replace the matched part with the designated file path. If root is the path for the site and a folder has a more specific alias, changing the site root does not necessarily change requests under that mapped prefix. Read the selected location before computing the physical path.

For example, a root under /srv/course and a request for /forms/guide.txt ordinarily map into its forms subdirectory. With a directory alias attached to the forms prefix, the same request can instead use /srv/shared/guide.txt. Check the presence of the intended file, any permitted filesystem traversal and a body marker from the exact location. An internal redirect caused by an index or fallback may also start a new location search. A request for the directory route can ultimately use a different handler from a named file test.

In a flat Nginx configuration, which of an exact rule, prefix and regex wins?

An exact path stops the usual location search when it matches. Otherwise Nginx remembers the longest suitable prefix. In a straightforward set of exact, prefix and regex locations, it evaluates applicable regular expressions unless the chosen prefix carries the modifier that suppresses that search. The first matching regex can then handle the request, or the remembered prefix applies if none wins. Newer releases and nested locations can require additional reasoning. Use the installed version's documentation and test the actual rules rather than memorizing that the longest line or the first declaration always wins.

Give concrete input. The exact path /files/priority.txt can use a dedicated response. A neighbor route under the ordinary files prefix can match a broader text regex. A path under an assets prefix specifically marked to skip regex can serve the ordinary file. Query data need not change these path choices. When a directory index redirects internally to a concrete filename, repeat this trace for the new URI. The Nginx configuration reading lab shows these responses for one named listener.

The folder URL returns 403, but a file inside the folder is readable. Is that consistent?

Yes. A request addressed to a folder can depend on index candidates and automatic listing. If there is no eligible default document and listing is disabled, that request can be refused while a direct named file is authorized and readable. Apache's Options setting and Nginx's autoindex control directory listing in their applicable context. Turning listing off is not a policy that denies direct access to every individual child. Compare both requests under the same hostname, protocol and listener.

A useful response connects this to the deployment goal. If the intended folder route should open a landing page, add or correct its approved index and verify the body. If the directory and children are private, keep them outside the served tree or verify the actual scoped access restriction. Broad mode changes are not appropriate just because a folder view was forbidden. A third control for an unrelated location checks whether the policy was applied more widely than intended. Mention a known public child and a harmless reserved fixture if both matter to the requirement.

Deployment, diagnosis and recovery questions

What is the difference between a syntax check, a service reload and a verified rollout?

A syntax check reads a candidate using the selected executable and options. It can also check some references, but it is limited to that invocation and does not give results for all paths. A reload requests that the running service adopt updated instructions. The master may reject the candidate if an essential resource such as a new listener cannot be opened. On Nginx, successful activation starts workers for the new configuration and older workers can finish work under the preceding configuration. The service wrapper should use the procedure supported for that instance.

The rollout is verified when a fresh request on the intended route gets the planned status and content, and independent controls behave as expected. Review the applicable logs and confirm activation succeeded rather than inferring it from a successful signal delivery. If a valid candidate produces wrong behavior, restore the known compatible input, recheck and apply it, then prove the previous responses returned. If the candidate failed before activation, there may be no need to signal a still healthy service after fixing disk. This distinction makes the answer actionable during an actual change.

What does the Nginx configuration dump or Apache virtual host report actually show?

Both are read of candidate input for the requested invocation. Nginx's uppercase test option checks and prints included config files. Apache's uppercase S report can describe parsed virtual host groups and order under the startup settings. If an operator runs another binary, omits a path override or uses a different unit environment, a valid result can describe the wrong workload. Neither report is a complete export of active in-memory worker behavior. A candidate that was never activated can appear in a report while the old content still serves normally.

Start from the running listener, process and configured startup arguments. Follow any mounts or include links to the actual input. Use the scoped parser view to identify the candidate and compare the active behavior after verifying activation. If the service authorizes a comparison across environments, retain one concise excerpt with relevant file boundaries and host rather than dumping credentials or all internal settings into a shared message. The useful result is a chain from process to input to observed response.

How do you distinguish an inaccessible upstream and a slow upstream?

Identify which component produced the 502 or 504 and inspect the gateway's selected address, port and applicable protocol. A refused connection to a configured upstream may leave no arrival at the application, as it did in the diagnostic exercise. An upstream that logs arrival but withholds its response can exceed the gateway's wait and produce 504. The precise protocol rules and configuration matter. A code alone cannot tell you whether a database, network, application or another proxy caused the problem.

Use a working control and compare the failed route with an authorized direct test from the proxy's network context. Check the exact address and timing. A local healthy response at the intended application port can show that a stale gateway target is wrong, but if network namespaces differ your interactive shell may not share the same route. For a timeout, correlate arrival and duration across hops. A read timeout between received bytes is distinct from a total request duration. Adjust the real failure cause or justify a route-specific budget when the operation genuinely needs it.

A reload says success and the visitor sees yesterday's page. What evidence separates three possible causes?

First verify the candidate contains the expected origin source and site name. If it does not, find the real included file or source. Second, use a controlled request to the intended origin with the exact name, path and port. If it still serves the old marker, check live activation, the selected host and any more specific location before changing a new variable. Third, if origin is current but public use differs, inspect the public route, cache and selected backend. Which request arrived where is useful evidence, and response headers can explain whether a representation was reused.

A single test should not change authority, address and path all at once. To keep the comparison reliable, carry the same identifying marker and specific time. For example, the earlier homepage and today’s homepage may both return 200 and the same Server header. A meaningful response body or expected version marker distinguishes them. A long-lived permanent redirect or public cache can supply an old route even after a correct server restarts. Explain those behaviors independently, then repeat the ordinary user-facing route to verify recovery.

What belongs in a one-site change plan on a shared host?

Record the exact active input, service instance, address and name, plus the authorized request that will prove success. Back up the managed configuration outside active includes, verify its bytes and record any enablement symlink or source metadata. Identify the dependencies and the previous content artifact needed for recovery. Limit modifications to the intended site settings. A shared default, listener or worker option can affect more than one site even when the patch appears close to the desired block.

Define acceptance using the changed site marker, an independent site and relevant expected failures. An intentionally unmatched name or denied fixture can show that a scoped change did not broaden access. Test the candidate and use the approved activation method. Validate both live behavior and source consistency. If a shared dependency fails or an independent result changes, start the prepared rollback and check its restored behavior before widening scope. Give a concrete criterion, such as correct file body on the partner path and stable library marker on the same listener.

Reverse proxy and application delivery questions

What does a reverse proxy need from a local Spring Boot or Node application?

The proxy needs a reachable application endpoint that uses the expected protocol, address, port and path. Inspect what the application actually binds. A framework name or sample port is only a starting clue. A private HTTP application can listen on loopback when the proxy is on the same machine. If they run in separate containers, loopback often refers to separate network namespaces, so choose an approved network path that the proxy can reach.

Choose which request paths the proxy should forward, and how to form the upstream Host and path. Test one direct private route and one through the normal listener. Use lightweight markers to verify whether the path and authority arrive as intended. Forwarded address and protocol headers have to be set and interpreted with an explicit trust boundary. A client can supply values that an upstream should not trust without knowing the trusted proxy's behavior. Describe how the intended public access and downstream listening scope fit together, and verify redirects, readiness and actual content independently.

How can Nginx or Apache serve PHP dynamically instead of returning the script file?

The web server selects a handler appropriate to the requested URL. When a deployment uses PHP-FPM, that web server can talk to it using FastCGI, a protocol distinct from ordinary browser HTTP. Nginx can use fastcgi_pass with the actual socket or endpoint and the parameters the FPM pool needs, including correct script filename mapping. Don't rely on a packaged include filename without checking its contents. Apache installations can route to FPM through their chosen handler and modules. Ensure private source paths cannot be unintentionally returned as static content.

Verify the listener or socket and access from the actual web server process. Confirm the physical file mapped for a permitted route and that an approved harmless request returns an executed result. Check the negative behavior for missing or disallowed input. If a running service actually serves source, use the approved incident procedure. A working static response is only evidence that the web server found bytes. The required result is the application performing the safe, expected action through its handler.

When is it appropriate to fall back to index.html for React or Angular routes?

A client-routed static single-page deployment can need its entry document when someone directly opens a supported deep route. The browser downloads that document and its scripts and uses the path to display the desired screen. A try_files fallback to the entry document can be appropriate in that scope. Frameworks can instead use server rendering, pre-rendering or mixed configurations. Read the actual build output and runtime design before assuming all routes are static. The stable concept is to route each kind of path to the intended handler.

Compare a known application route opened directly, a present static asset, a missing script or stylesheet, and a normal API request. Returning HTML for an absent script can cause confusing browser errors even if that request reports 200. An API designed to return its own 404 should not accidentally receive an HTML shell. A server-rendered page needs its actual render target and readiness checks. Check content type, status and body for each kind of request so a generic success cannot conceal a routing problem.

What is Apache's equivalent of a simple Nginx reverse proxy?

Apache can route HTTP through mod_proxy with the HTTP protocol module and a scoped ProxyPass configuration. ProxyPassReverse is commonly appropriate to rewrite certain backend redirect headers for the public proxy route. It is not a universal rewrite of links in response bodies. Use the correct deployed host and port, and avoid enabling an unrestricted forward proxy. In Nginx, proxy_pass has its own path rewriting behavior depending on whether a replacement URI is present. Verify the expected request and returned Location values on either engine.

Give a simple operation. Allow one public prefix to reach a synthetic backend path and keep a static prefix local. Test the exact method, path and hostname. Then check an app redirect and a returned error to distinguish who handled each. If a proxy applies a timeout or retry, check the real scoped setting and the upstream logs. A single HTTP 200 does not prove headers, original URLs or negative branches kept the intended relationship.

How would you discuss a login rate limit without claiming a fixed outcome for 20 requests?

An Nginx rate-limit zone defines a key, memory zone and request rate. The selected location applies that zone with its burst and delay policy. Actual outcomes depend on timing, key and configured limit, including whether a dry run is active. Choose a caller identity only after understanding trusted proxy headers and how several users can share one network source. A status can be configured for rejections. Rate limiting controls a particular consumption pattern and does not implement user authentication.

In a private training fixture, compare a normal sequence and a deliberately controlled faster sequence for the same test key. Record accepted, delayed and rejected requests along with how closely they were sent and the configured status. Check that an unrelated route still responds. Do not promise that a loop will yield a particular number of errors on every host. A useful answer connects the measurements and expected result to the actual rule and log evidence. Production limits can affect legitimate users, so scope them and review the acceptance policy before broad rollout.

HTTP settings and acceptance evidence questions

What difference should you observe between a gzip response and a plain response?

A compatible client can offer gzip in Accept-Encoding. If the selected route uses compressed transfer, the response includes Content-Encoding describing the encoded representation. The decoded data should be identical to the ordinary content. A cache that stores different representations needs the relevant variation information, such as Vary on Accept-Encoding. A small or already compressed response may not be a candidate for the same reduction observed on long repetitive text.

Explain how you would test it. Use the same asset URL from the same intended host. Save the response headers and both bodies while requesting identity and gzip. Decode the encoded body and compare it byte for byte to the ordinary one. Read Vary and cache policy along with the sizes. A HEAD request can show some headers but cannot prove the encoded and decoded bytes match. With a shared proxy, compare which layer encoded and cached the body if you need attribution.

What do you verify for a legacy URL redirect and a freshness policy?

Check the redirect status and exact Location on the original request. Then separately verify the new URL and its actual body, including any required path and query. Use an explicit approved canonical authority. The target TLS and availability still matter after the first response succeeds. Permanent redirects may persist in caches. A supported alternate name reached over HTTPS needs working certificate coverage even if its only response is a redirect.

For a freshness policy, check the selected representation's Cache-Control and actual route. Max-age can permit ordinary reuse during freshness. No-cache allows supported storage but requires successful validation before reuse; no-store instructs caches to avoid storing the response. Private data and compiled static assets often have different requirements. Explain a realistic test for each. Under a validator check, a matching saved representation can result in 304 and reuse of the previously saved body. A fresh candidate response offers separate evidence for changed content.

How do you trace an upload limit from the browser to an application?

Compare a known accepted request and a bounded rejected request with the same endpoint, method and content encoding. Measure the complete request body. Multi-part forms add fields and framing, so the largest submitted file is not always exactly the body's length. An Nginx location limit, intermediary or application may reject it, and a runtime can have both a whole-POST limit and a per-file limit. An observed 413 does not report which layer made the decision by itself.

Find the request in the relevant gateway logs and look for a corresponding application event. If the app sees the small request and never sees the larger one, inspect the earlier enforcing hop. If the app sees both and rejects one, inspect its own runtime and allowed inputs. Adjust only the policy supported by the expected business size and resource effects. Verify below, at, and above the intended boundary when it matters. The HTTP settings lab gives a local measurement of exact received bytes.

Demonstrate why two successful bodies can mean different things

Use this short isolated Nginx test as a practice answer. Run it as a regular user inside a disposable Bash shell with curl and Nginx installed. It opens only loopback port 18898 and uses a generated config and content directory. Choose a different unused high port and replace its references if necessary. The fixture intentionally sends the application shell for a missing file inside the client-routed prefix. A separate asset prefix returns the correct 404 on a missing asset. This makes a generic success easier to challenge in an interview.

if [ "$(id -u)" -eq 0 ]; then
  printf 'Use a regular practice account.\n' >&2
  exit 1
fi
nginx_bin=$(command -v nginx) || exit 1
interview_lab=$(mktemp -d /tmp/rb-web-interview.XXXXXX) || exit 1
lab_pid=
interview_cleanup() {
  if [ -n "$lab_pid" ] && kill -0 "$lab_pid" 2>/dev/null; then
    kill -QUIT "$lab_pid"
    wait "$lab_pid" 2>/dev/null || :
  fi
  case "$interview_lab" in
    /tmp/rb-web-interview.??????) rm -r -- "$interview_lab" ;;
  esac
}
trap interview_cleanup EXIT
mkdir -p "$interview_lab/public/assets"
printf '<p>application-shell</p>\n' > "$interview_lab/public/index.html"
printf 'p { color: navy; }\n' > "$interview_lab/public/assets/style.css"
cat > "$interview_lab/nginx.conf" <<'NGINX'
worker_processes 1;
pid nginx.pid;
error_log error.log notice;
events { worker_connections 32; }
http {
    types { text/html html; text/css css; }
    default_type text/plain;
    client_body_temp_path body;
    proxy_temp_path proxy;
    fastcgi_temp_path fastcgi;
    uwsgi_temp_path uwsgi;
    scgi_temp_path scgi;
    access_log access.log;
    server {
        listen 127.0.0.1:18898 default_server;
        server_name fallback.test;
        return 404 "unmatched-host\n";
    }
    server {
        listen 127.0.0.1:18898;
        server_name academy.test;
        root public;
        location /app/ { try_files $uri /index.html; }
        location /assets/ { try_files $uri =404; }
        location / { try_files $uri =404; }
    }
}
NGINX
"$nginx_bin" -e stderr -p "$interview_lab/" -c "$interview_lab/nginx.conf" -t || exit 1
"$nginx_bin" -e stderr -p "$interview_lab/" -c "$interview_lab/nginx.conf" -g 'daemon off;' &
lab_pid=$!
for attempt in 1 2 3 4 5 6 7 8 9 10; do
  if [ -s "$interview_lab/nginx.pid" ]; then break; fi
  if ! kill -0 "$lab_pid" 2>/dev/null; then break; fi
  sleep 0.2
done
if ! kill -0 "$lab_pid" 2>/dev/null ||
   [ ! -s "$interview_lab/nginx.pid" ] ||
   [ "$(tr -d '[:space:]' < "$interview_lab/nginx.pid")" != "$lab_pid" ]; then
  printf 'The private listener did not start. Check the chosen port.\n' >&2
  exit 1
fi

Each request keeps the same connection target and authority except the final fallback control. Save the response headers and body marker. The conceptual document path under the application prefix is meant to receive the shell. A browser would separately use a bundled script to interpret that path in a complete app. There is no actual React or Angular build here. The missing script under the same application prefix is not meant to receive HTML, yet its indistinct fallback causes just that result. An independent asset prefix helps show how the missing-file policies differ.

answer_probe() {
  local host=$1 route=$2
  printf '\n%s %s\n' "$host" "$route"
  curl --noproxy '*' --max-time 5 -sS --resolve "$host:18898:127.0.0.1" \
    -o "$interview_lab/probe.body" \
    -w 'HTTP %{http_code} type=%{content_type} endpoint=%{remote_ip}:%{remote_port}\n' \
    "http://$host:18898$route" || return
  head -c 90 "$interview_lab/probe.body"
  printf '\n'
}
answer_probe academy.test /app/lessons/week-one
answer_probe academy.test /assets/style.css
answer_probe academy.test /assets/absent.css
answer_probe academy.test /app/absent.js
answer_probe unknown.test /app/lessons/week-one

Report the two HTML 200 responses separately. For the application route HTML is the intended representation. For the missing script it is an erroneous success from the fallback. The existing style served as text/css, the missing asset under the explicit asset route returned 404, and the unrecognized authority also got 404 with the different fallback marker. The two 404 responses have different meanings even though the status matches. Use these outputs to answer what your next route checks would be before modifying a production application.

interview_cleanup
trap - EXIT
test ! -e "$interview_lab" && printf 'Interview practice lab removed.\n'

Save the status and content-type worksheet before running cleanup. For a thought exercise, move only actual bundled assets to a distinct URL prefix as part of a defined build output and make that prefix fail normally for missing files. Verify both the direct deep-route entry and missing-script behavior. A live application needs actual route-aware testing. The fixture demonstrates the difference between HTTP body types and successful protocol responses using ordinary static content.

Practice a short diagnosis and defend each conclusion

Take sixty seconds to give your first answer to the staged result. The prompt is that a JavaScript file was reported as loaded but the page is broken. A focused answer describes the intended resource type, the received HTML shell and the shared client route prefix. It does not begin by announcing that Nginx is broken or that the JavaScript engine is down. Mention the exact test outcomes you observed. A successful status arrived from the appropriate listener, but the bytes belong to the fallback. The direct stylesheet and the missing-file response from the explicit asset prefix supply two controls.

In a second attempt, imagine the interviewer asks how to prove the public user took the same route. Start by naming the expected authority, port and listener. The short fixture writes curl's remote address and port so that hidden routing differences are easier to detect. For an ordinary service capture both its front-door test and an approved origin comparison, keeping the HTTPS hostname and expected name validation intact. Observe whether the proxy forwarded the original host and path. Compare request and log times, and preserve the distinction between the controlled local check and the publicly advertised route. If the test lacked a real build and backend, be explicit about that limitation.

Solve a second problem in reverse. The site owner reports that a cache change broke the new CSS. A CSS URL now returns a 200 with the HTML shell. Before concluding that timeout or revalidation caused it, check the actual routing and content type. If the native app sent the intended stylesheet URL but the gateway selected the page shell, correct the path policy. If the client received old CSS but the server returns new CSS directly, inspect cache headers and assets, then verify a release with a fresh asset path where appropriate. Matching the report to the response goal avoids combining two different classes of failure into one patch.

For a small-scope recovery discussion, compare the result if a fresh candidate added just one new asset location. Plan a syntax check, proof that the allowed stylesheet still serves, a missing asset that now returns the intended error, and preservation of the deep route. Also include the old default for a mismatch. Save the active source outside any include before making a real change. If an unrelated route changes or the desired body is absent, you need the known previous state and an observable acceptance condition for recovery. A well-scoped answer includes what you would restore and how you would prove it.

An interview answer can be graded by the evidence it names
SkillWhat to stateWeak shortcut to catch
SelectionConnection endpoint, authority, effective site and locationAssume a server response came from the expected host
AttributionComponent that emitted the status, relevant target and a matching log or markerDiagnose a whole stack from one status
ValidationExact candidate parse and fresh named request with correct body and independent controlsDeclare success from syntax or any two hundred status
RecoveryKnown compatible input and same probe verifying restored behaviorStop after copying a backup without checking the actual response

Quick quiz and revision cards

  1. An HTTPS alternate hostname should immediately redirect. The destination has a valid certificate, but the alternate name triggers a certificate warning first. What should be checked?

    1. The certificate and TLS listener selected for the initial alternate name
    2. Only the final destination certificate
    3. Whether the application sends an HTML index
    Check the first answer

    A. A client needs a trusted TLS connection for the first name before relying on that connection's HTTP redirect. Check the actual TLS termination point.

  2. Which observation shows the static script was not served as the intended type?

    1. The expected authority was sent
    2. The response reports HTML and contains the application shell instead of script bytes
    3. The TCP connection succeeded to a reachable port
    Check the second answer

    B. A matching endpoint and a successful status only show that a responding service handled the input. The media type and body attach the observed problem to the route's selected behavior.

  3. A gateway logs a refused TCP connection at the configured upstream and that app saw nothing. What is the next focused check?

    1. A common framework default regardless of deployment
    2. The database version displayed in an earlier error
    3. Whether the configured address and port are reachable from the gateway and the intended process listens there
    Check the third answer

    C. Attribute the transport error to the attempted upstream hop first. Compare the expected socket with the configuration and observe the intended response after a scoped correction.

Separate the connection and name

Determine the listener first, then inspect the host and selected site. Layer TLS and certificate selection in front of the HTTP routing when needed.

Map the selected route

Know whether the rule reads a file, internally selects an index, redirects the client or talks to an upstream application.

Explain the next check

Use a comparison that distinguishes two plausible causes. State the expected result and what a contrary result would imply.

Prove the recovered behavior

A checked file and a signaled process are stages. The intended response, negative checks and stable controls finish the proof.

Primary references