Chapter 8: Configuring Nginx and Apache
8.6 Task: run a site on a different port
A dairy may use another port, such as 8081, for a preview or internal tool. A port separates endpoints. Restrict the access path and authenticate users separately.
डेअरीच्या preview किंवा internal tool साठी 8081 सारखा वेगळा पोर्ट वापरता येतो. तो endpoint वेगळा करतो. कोणाला प्रवेश मिळेल आणि वापरकर्ता कोण आहे हे वेगळ्या नियमांनी तपासा.
डेयरी की preview या internal tool के लिए 8081 जैसा अलग पोर्ट इस्तेमाल हो सकता है। इससे endpoint अलग होता है। पहुँच और उपयोगकर्ता की पहचान अलग नियमों से तय करें।
For a local Nginx preview, declare the intended loopback port inside its server block, for example listen 127.0.0.1:8081;. With Apache, the equivalent endpoint needs a main Listen 127.0.0.1:8081 directive and a matching virtual host. A VirtualHost declaration alone cannot open a socket. Use one service per ordinary bound address and port.
Test the candidate using the same program and startup settings as the service, then inspect the running socket and use the intended hostname. Loopback does not require an inbound cloud rule. If a direct remote route is actually part of the design, check the intended bind, network controls and user authorization. On an enforcing SELinux host, inspect existing port policy and denial evidence when a bind is refused.
Ravindra Bagale's Tip
Test the listener locally first. If a permitted direct connection still fails, check the expected bind address and network path before changing a cloud security group or host firewall. Private forwarding and proxy designs can keep the application port off the public interface.
Ravindra Bagale's Tip – मराठी
आधी listener ची local चाचणी करा. अधिकृत direct connection चालत नसेल तर security group किंवा firewall बदलण्याआधी bind address आणि network path तपासा. Private proxy किंवा forwarding साठी application port सार्वजनिक करावा लागत नाही.
Ravindra Bagale's Tip – हिंदी
पहले listener को स्थानीय रूप से जाँचें। अधिकृत direct connection फिर भी न चले तो security group या firewall बदलने से पहले bind address और network path की जाँच करें। Private proxy या forwarding में application port सार्वजनिक करना ज़रूरी नहीं।
Lab
Use the two temporary local servers below to compare two valid listeners and a virtual host whose port is not listening. Verify the connection and response without exposing an admin site.
Plan a separate listener and its access path
The diagram illustrates one design for approved access from a known office network. A loopback preview, managed tunnel or authenticated proxy can use a different access path.
- Choose the intended address and an unused port.
- Set the listener and the necessary site rule.
- Test and activate the candidate using the service workflow.
- Check the exact listener address and request the expected hostname.
- If direct remote access is intended, confirm applicable network and user access controls with authorized tests.
Example ports for application processes
Application port numbers can be configured. Check the deployment before relying on an example below. A same-host proxy can reach an upstream on loopback.
Tomcat / Spring Boot
8080 is one commonly used HTTP endpoint. Verify the installation configuration and actual bind.
ASP.NET Core
5000 and 8080 are possible ports. Confirm the application and container settings for the deployment.
Node.js / Express
3000 is one example. Read the configured port and address.
Python application servers
5000 and 8000 are common example ports. Use a loopback bind for a same-host private test.
Databases: MySQL 3306, PostgreSQL 5432, MongoDB 27017, Redis 6379
Keep database connections on approved private paths with the necessary network and database authorization.
Managed private access
With AWS Systems Manager and its prerequisites in place, use an authorized Session Manager forwarding session to reach the managed node without opening direct public access to the application port. Follow the AWS procedure for the permitted instance, suitable agent, local plugin and caller role.
Access to a staff preview
Use the application access checks that the service requires alongside its approved network path. An office network address does not identify a particular authorized employee.
Recap
- Verify the actual listener and intended host.
- Choose the approved access path and authenticate users where required.
Use another port to give a service a distinct connection endpoint
A small dairy has a public website and a preview of next month's catalog. Staff want to review the preview before the public rollout. On the training machine the current website and preview will be represented by two harmless text markers. They can use the same hostname in a controlled lab while receiving connections on different ports. A different port makes the connections distinguishable. It does not authenticate staff, constrain which networks can reach a broadly bound service, or encrypt HTTP. Plan the endpoint first, then verify access and authorization separately.
A port is a numbered part of a network endpoint. An IP address identifies a network destination and a port identifies a particular place where a program may accept traffic at that address. For the TCP connections in this lesson, a listener is a socket an application has asked the operating system to accept connections on. A socket is an operating-system interface to network communication. A familiar port is a convention. HTTP clients normally use port 80 for a URL whose scheme is HTTP and lacks an explicit port. HTTPS normally uses 443. You can run plain HTTP or correctly configured HTTPS on another port. Changing the number alone never changes the protocol.
Use the simple example http://preview.test:18886/marker.txt. The first part tells the client to use plain HTTP. The hostname identifies the expected name and is ordinarily resolved to an address. The colon and number designate the destination port. The final path selects the requested content. In this example the client will override resolution to use its own loopback address. One request uses port 18886 and another uses 18887. They have the same scheme, name and path. The port is the only changed input, so different response markers demonstrate that two distinct listener endpoints did different work.
Many explanations treat a different port as though it were just a second password. Anyone reaching a listener with permission to connect can send a request regardless of whether they knew the number beforehand. You need a deliberate access design. In the lab both listeners are bound to IPv4 loopback, which routes traffic back inside the same machine. For a real preview, teams may choose a loopback-only upstream behind an authenticated reverse proxy, a private network route with trusted clients, or a supported management tunnel. The real design can also need HTTPS, application authorization and monitoring, depending on what the preview exposes. A network source restriction and a user's application rights answer separate questions.
A reverse proxy is a server that receives requests on behalf of another service and forwards selected work to that service. If it is on the same machine as the upstream, the upstream can commonly listen only on loopback. External visitors connect to the proxy's intended public address and never require a direct inbound connection to the upstream port. A private preview can instead use the organization’s existing controlled access channel. Decide who should connect to which endpoint and how the application verifies them before choosing whether a new public listener is necessary.
Read the bind address alongside the port number
In Nginx's ordinary HTTP setup, a listen directive inside a server block gives an address and port where that virtual server is eligible to receive requests. Several server blocks can share the same listening endpoint when appropriate. Their names distinguish requests within the selected endpoint. A bind to 127.0.0.1:18886 is intentionally local to the machine. A broad wildcard bind such as a port by itself can cover more interfaces, subject to the installed server and operating-system conventions. IPv6 needs explicit consideration. The IPv6 loopback address is ::1, and the same text written without brackets is ambiguous when a port follows it.
Apache separates its listener from its site descriptions. The main Listen directive opens the endpoint. A VirtualHost group says which site policy to use on an eligible endpoint. The lab config deliberately contains a named virtual host on a third port without a corresponding Listen directive. Apache can show that definition in its parsed host report. A client still cannot establish a connection at that endpoint, because the declaration did not open a socket. That result teaches more than copying both lines at once. It lets you change one mechanism and see the missing dependency in the expected output.
# Concept sketch, not a system configuration.
# Nginx uses listen within its chosen server block.
listen 127.0.0.1:18886;
# Apache opens the endpoint with Listen outside a VirtualHost.
Listen 127.0.0.1:18887
<VirtualHost 127.0.0.1:18887>
ServerName preview.test
</VirtualHost>
Grouping each port with its address is important on machines that have both a public-facing route and a private address. A service bound to loopback cannot normally receive a packet addressed to the network interface of that same machine. A private network bind can receive traffic from other machines that have a route to it and permission to use it. An all-interface bind can include an interface the operator did not originally consider. Read the actual socket list after starting rather than inferring the effective scope from a port label in a file.
Two independent processes usually cannot claim the same address, port and transport simultaneously under ordinary settings. If a service reports a bind error, identify the listener already occupying the address and port. It might be an existing web service, a long-running lab, or another application using a conventional development port. Some operating systems and application settings support more advanced socket sharing, but the lab uses ordinary exclusive binds. Do not stop the other process to make the exercise pass. Choose free high ports and consistently adapt the corresponding URLs and config.
An address change can introduce an overlap even where you think the port stayed the same. Suppose a service listens on one explicit address. A proposed wildcard bind can overlap the specific socket. Apache documents that some overlapping changes require an approved full stop and start rather than a graceful change because existing sockets remain available during restart. Avoid experimenting on a managed service. For this lab choose known isolated addresses, open both child processes independently, and observe their listeners before testing any application body.
Follow the previous configuration discovery lesson if you do not know which process received a request. On Linux, the socket list with listening, TCP, numeric and process options can show where it is bound and who owns it where permissions allow. On macOS an installed socket listing utility can give a similar read-only view. The key result is the exact address and port, not merely a string match on the port number. An IPv4 listener shown and tested from the same shell will not by itself prove that IPv6 clients or remote LAN clients can connect.
Separate a missing listener from a blocked network path
Think of the path as a set of decisions. The client chooses a hostname, address and destination port. Network routing must reach that address. If the service is in a cloud environment, security controls on the route may accept or discard the packets. The host policy may allow or deny the attempt. A process must be listening on the chosen local address and port, and the application still must select a valid request rule. After establishing each stage, choose the next check. Adding an AWS security-group rule does not create a listener, and moving a directive around does not make the public route suddenly allowed.
An AWS security group controls allowed traffic for the associated resource. Its rules can filter by protocol, port and source for inbound access. This differs from a network ACL, a subnet-level control that can also affect traffic and has its own rule evaluation and return behavior. The traffic still needs appropriate routes and any other access decisions such as a host firewall. Traffic to an application bound only to loopback normally does not arrive at that loopback endpoint through an instance's network interface merely because a security group has been changed. A supported private access path or proxy can be the intended way to reach it.
Start with a local probe against the intended address on the server. If the test gets a connection refusal, look for an actual listening socket and startup errors. In a local clean lab, a quick failure on an intentionally unused port means the expected socket is absent. In a real environment an active reject or intervening device can also cause a prompt refusal. A timeout only says the operation failed to complete in the time allowed. It can occur for several reasons, including an unresponsive service or filters and routing. Do not open a broad inbound rule solely because a browser displayed a timeout.
Once the local listener returns the expected content, test the next boundary appropriate to the plan. If an authenticated proxy fronts the site, verify a path through that proxy and a direct connection policy for the upstream. If a private training network should reach a bind address, verify from an authorized source on that network and confirm an unexpected source is denied through an approved controlled test. Keep authentication separate from an IP allowlist. A public NAT address can be used by multiple people. Knowing a request came from one network is different from knowing that its user may access a protected application.
An error from the web server is also different from failing to connect. A returned 403, 404 or 503 already means some HTTP service answered on the selected path. Inspect its headers, log entry and response body marker to identify the right program. A gateway can generate an error without the upstream responding. A raw port probe may show transport works while an HTTP request fails because the wrong protocol or virtual host was used. Keep a local and, when appropriate, a permitted external record. They should state what was observed at each layer.
Lab to compare a real listener and a parsed site with no listener
Use a practice machine with Bash, Python 3, curl, Nginx and Apache HTTP Server 2.4. A regular user runs the example from a separate Bash shell. It starts two local processes with independent configs, PIDs, working directories and log files. Both endpoints bind to IPv4 loopback. A third address and port will be mentioned in Apache's virtual host report but intentionally left unbound. This site is only a text fixture. It contains no administrative pages. The lab does not need a cloud instance, security group adjustment, administrator access or public routing.
Check that all three expected socket addresses are free first. The Python code asks the operating system to reserve each endpoint briefly, and the context closes each socket immediately. This is an availability check, not a guarantee that another program cannot take a port between the probe and start. If one is occupied, leave its process alone. Choose three different unused high ports and replace their exact references consistently in all steps, including the requests. Next, create an isolated parent directory for both servers, set aside independent temp and content paths, and write two markers.
if [ "$(id -u)" -eq 0 ]; then
printf 'Use a regular practice account.\n' >&2
exit 1
fi
nginx_bin=$(command -v nginx) || exit 1
apache_bin=$(command -v apache2 || command -v httpd) || exit 1
python3 - <<'PY'
import socket
for port in (18886, 18887, 18888):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as candidate:
candidate.bind(("127.0.0.1", port))
except OSError as exc:
raise SystemExit(f"Port {port} is unavailable: {exc}")
PY
test "$?" -eq 0 || exit 1
ports_lab=$(mktemp -d /tmp/rb-web-ports.XXXXXX) || exit 1
ng_pid=
ap_pid=
ports_cleanup() {
if [ -n "$ng_pid" ] && kill -0 "$ng_pid" 2>/dev/null; then
kill -QUIT "$ng_pid"
wait "$ng_pid" 2>/dev/null || :
fi
if [ -n "$ap_pid" ] && kill -0 "$ap_pid" 2>/dev/null; then
kill "$ap_pid"
wait "$ap_pid" 2>/dev/null || :
fi
case "$ports_lab" in
/tmp/rb-web-ports.??????) rm -r -- "$ports_lab" ;;
esac
}
trap ports_cleanup EXIT
mkdir -p "$ports_lab/ng/docs" "$ports_lab/ap/docs" "$ports_lab/ap/logs"
printf 'nginx-preview-marker\n' > "$ports_lab/ng/docs/marker.txt"
printf 'apache-preview-marker\n' > "$ports_lab/ap/docs/marker.txt"
The Nginx entry gives the site an explicit loopback listener. The path arguments ensure its runtime files belong to the experiment. Its server name is the same as the Apache case, so changing the port in the probe is enough to choose a different endpoint. The configuration checks can be run before making a single HTTP connection. Observe where the real behavior must still be tested after the start.
cat > "$ports_lab/ng/nginx.conf" <<'NGINX'
worker_processes 1;
pid nginx.pid;
error_log error.log notice;
events { worker_connections 32; }
http {
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:18886;
server_name preview.test;
root docs;
location / { try_files $uri =404; }
}
}
NGINX
"$nginx_bin" -e stderr -p "$ports_lab/ng/" -c "$ports_lab/ng/nginx.conf" -t || exit 1
Apache includes a separate Listen line for port 18887. It has a site definition for that endpoint and another definition for the unused one. The explicit change in the example is the missing Listen line. The parsed host report should still mention the other site group. The exercise does not add that socket dynamically. It checks that site definitions and live sockets are two different kinds of evidence. The module detection accommodates the usual alternatives of static and shared modules in package builds. If the installation keeps modules in a different place, locate the actual module directory before using the sample.
module_dir=
for candidate in /usr/lib/apache2/modules /usr/lib64/httpd/modules /usr/lib/httpd/modules /usr/libexec/apache2; do
if [ -r "$candidate/mod_authz_core.so" ]; then module_dir=$candidate; break; fi
done
if [ -z "$module_dir" ]; then
printf 'Locate the Apache package module directory before continuing.\n' >&2
exit 1
fi
compiled=$("$apache_bin" -l) || exit 1
add_module() {
local name=$1
if ! printf '%s\n' "$compiled" | grep -Eq "(^|[[:space:]])mod_${name}\.c$"; then
test -r "$module_dir/mod_$name.so" || return 1
printf 'LoadModule %s_module "%s/mod_%s.so"\n' "$name" "$module_dir" "$name"
fi
}
{
printf 'ServerRoot "%s"\n' "$ports_lab/ap"
if ! printf '%s\n' "$compiled" | grep -Eq '(^|[[:space:]])(event|worker|prefork|mpm_event|mpm_worker|mpm_prefork)\.c$'; then
add_module mpm_event || exit 1
fi
add_module unixd || exit 1
add_module authz_core || exit 1
cat <<APACHE
ServerName main.test
Listen 127.0.0.1:18887
User "#$(id -u)"
Group "#$(id -g)"
PidFile "$ports_lab/ap/apache.pid"
DefaultRuntimeDir "$ports_lab/ap"
ErrorLog "$ports_lab/ap/logs/error.log"
<Directory />
Require all denied
AllowOverride None
</Directory>
<Directory "$ports_lab/ap/docs">
Require all granted
</Directory>
<VirtualHost 127.0.0.1:18887>
ServerName preview.test
DocumentRoot "$ports_lab/ap/docs"
</VirtualHost>
<VirtualHost 127.0.0.1:18888>
ServerName declared-only.test
DocumentRoot "$ports_lab/ap/docs"
</VirtualHost>
APACHE
} > "$ports_lab/ap/httpd.conf"
"$apache_bin" -f "$ports_lab/ap/httpd.conf" -t || exit 1
"$apache_bin" -f "$ports_lab/ap/httpd.conf" -S || exit 1
Start each process with its own entry file and one child identifier from Bash. Check both PID files. When the files match your two children you can connect to their actual listener addresses. When one child exits or never writes its PID, read local errors and stop the comparison before making requests. A partial lab might otherwise leave one service running while a third unrelated program answers a path that looks familiar. The cleanup trap owns both children and handles a failure after either one starts.
"$nginx_bin" -e stderr -p "$ports_lab/ng/" -c "$ports_lab/ng/nginx.conf" -g 'daemon off;' &
ng_pid=$!
"$apache_bin" -f "$ports_lab/ap/httpd.conf" -DFOREGROUND &
ap_pid=$!
await_owned_pid() {
local child=$1 file=$2
for attempt in 1 2 3 4 5 6 7 8 9 10; do
if [ -s "$file" ] && kill -0 "$child" 2>/dev/null &&
[ "$(tr -d '[:space:]' < "$file")" = "$child" ]; then
return 0
fi
if ! kill -0 "$child" 2>/dev/null; then break; fi
sleep 0.2
done
printf 'An isolated process did not start. Inspect its local bind errors.\n' >&2
return 1
}
if ! await_owned_pid "$ng_pid" "$ports_lab/ng/nginx.pid" ||
! await_owned_pid "$ap_pid" "$ports_lab/ap/apache.pid"; then
for log in "$ports_lab/ng/error.log" "$ports_lab/ap/logs/error.log"; do
if [ -r "$log" ]; then tail -n 8 "$log" >&2; fi
done
exit 1
fi
Now compare the two reachable services with the same hostname and path. The resolve option sends each one to loopback for its own port without modifying system name resolution, and the URL retains both explicit inputs. The no-proxy flag keeps the lab within your machine. The third probe names the declared-only host, and curl should fail to connect. The short timeout bounds the negative test. Curl's status display of 000 says it did not receive an HTTP status. Its process exit status of 7 indicates it could not connect in this clean local test. HTTP 000 is not a response sent by either web server.
probe_port() {
local host=$1 port=$2 result=0
printf '\n%s port %s\n' "$host" "$port"
curl --noproxy '*' --connect-timeout 2 --max-time 4 -sS \
--resolve "$host:$port:127.0.0.1" -w '\nHTTP status %{http_code}\n' \
"http://$host:$port/marker.txt" || result=$?
printf 'curl exit status %s\n' "$result"
}
probe_port preview.test 18886
probe_port preview.test 18887
probe_port declared-only.test 18888
if command -v ss >/dev/null 2>&1; then
ss -ltnp | awk 'NR==1 || $4 ~ /:(18886|18887|18888)$/'
fi
You should see the Nginx marker with HTTP 200 on the first endpoint and the Apache marker with HTTP 200 on the second. The last probe should yield a connection failure. On Linux the socket view should show loopback on the first two ports and no row for the third. A printed process column can vary with permissions. Compare that result with the earlier Apache host report, which names the unused declared-only endpoint. One is a list of live sockets. The other describes configuration groups that could apply if their destination became reachable.
Keep the three result lines and the host report for your worksheet. Then stop only the two experimental processes and remove the temporary directory. If you repeat the curl probes afterward, neither original marker should be returned from these private children. Avoid checking a port after teardown by assuming it cannot be reused. The direct cleanup proof is that the identifiers belonged to your exited children and the generated directory is gone.
ports_cleanup
trap - EXIT
test ! -e "$ports_lab" && printf 'Private port lab removed.\n'
Turn the declared-only site into a second private Apache endpoint
Repeat this optional extension before the cleanup block on a fresh run. You have already observed the expected no-listener result. Now promote that third endpoint only inside the private lab. The exercise deliberately adds the missing global Listen line and keeps the site's definition, content and authority the same. This tests the hypothesis that the socket, rather than site name matching, was the missing dependency. The original Nginx process should remain running on its own port throughout the comparison.
Copy the Apache entry to a second private file before adding the new line. The copy uses the same runtime directory, site declarations and content. The test reads the candidate without applying it. Since both entries would attempt to bind the original Apache endpoint, stop and wait for the old lab child before starting the candidate. Do not run both Apache copies at once. The named wait helper is already in this Bash shell from the start step. It ensures that the new Apache child owns the same private PID path before you make probes. The ordinary system service is independent of these two scratch files.
candidate="$ports_lab/ap/httpd-two-ports.conf"
cp -p -- "$ports_lab/ap/httpd.conf" "$candidate" || exit 1
printf 'Listen 127.0.0.1:18888\n' >> "$candidate"
"$apache_bin" -f "$candidate" -t || exit 1
kill "$ap_pid" || exit 1
wait "$ap_pid" 2>/dev/null || :
ap_pid=
"$apache_bin" -f "$candidate" -DFOREGROUND &
ap_pid=$!
await_owned_pid "$ap_pid" "$ports_lab/ap/apache.pid" || exit 1
probe_port declared-only.test 18888
probe_port preview.test 18887
probe_port preview.test 18886
The newly listening endpoint should now return 200 and the Apache marker. It uses the same Apache document directory as the existing site, so the marker agreement is expected. The earlier Apache endpoint should keep returning its Apache marker. Nginx should still return the independent Nginx marker. Before the change, the configuration already described the third host while no connection could be established. After the change, the same names and content yield a live response because the port binding became real. This distinction helps when an operator edits a virtual-host section but forgets to examine listeners.
The extension uses a stop and start scoped to a short-lived fixture so listener ownership is simple. A real listener change might have availability requirements and existing socket overlaps. Review the server's documented behavior and the service's standard activation procedure before proposing changes. Check whether original and proposed endpoints overlap, and plan an independent verification for the existing site. The exact maintenance method can affect clients even when both old and new configs pass their parser checks.
Write the old and new socket observations next to the unchanged site declaration. A colleague should be able to identify one actual input that changed. If your second endpoint fails to start despite a successful parser check, inspect the log for a bind conflict that appeared since the preflight. Failed activation can leave a new candidate on disk without an active child. In this scratch example you can end the experiment cleanly and repeat with free ports. On a managed server that same point calls for the approved rollback plan rather than retrying until another process releases its address.
Diagnose failures in the same order a connection travels
A client error and a server error can be minutes apart in a browser, but they should lead you to different evidence. Suppose you know the private preview should answer on a local high port. The syntax test works, the named virtual host is listed, and curl reports that the connection was refused. Go directly to the running process and listener. Check whether the address is right, whether the service started, and whether a different service occupies the endpoint. A configuration search for the hostname is not the next discriminating test, because it will repeat a fact you already know. The missing socket in the lab gives a clear example of correct parsing without a service to handle the destination.
Suppose instead the local request returns the preview marker, but the same port times out from an authorized office network. Verify that the remote client actually uses the same intended port and protocol. A browser following a redirect could reach a different endpoint. Find the address the client is using and compare it to the local bind. If the operator intentionally bound to loopback for a proxy, a direct remote probe will be the wrong test. Use the accepted route through the proxy or tunnel. If a documented design allows direct private access, inspect the network route, security group, subnet rules and operating system filtering for that endpoint. Keep the source interface and source address explicit because public or VPN traffic may take different paths.
Make a separate note of whether you tested a local, private, or public address. Many cloud instances are assigned a private interface address even when clients have a public address through a provider's mapping. A program generally binds to an address actually present on the host. Trying to bind the externally advertised address directly can fail if the host does not own it as a local address. Check the machine's interface list, then the accepted network design. Replacing that bind with every-interface access without review can exceed the intended scope. Binding correctly and accepting inbound traffic are two different choices.
If the service logs say address already in use, check who owns the socket rather than repeatedly changing request headers. Name-based virtual hosting can make multiple websites share one process and listener by design, as the next lesson illustrates. Two independent server processes with an ordinary bind cannot rely on hostname to avoid an address conflict, because that information is read after a connection arrives. If an existing Nginx site should front Apache, use an agreed private endpoint for the downstream Apache server and verify which process handled each hop. Each program uses its own error and access logs.
Another start error is permission denied at bind. Check the exact address and port and the process identity. Some systems restrict low numbered ports or use service policies and Linux capabilities to authorize binding. An enforcing SELinux system can also use a policy that limits which ports the confined web server may listen on. Check existing labels and denial evidence before requesting a persistent policy update. A port can already belong to a different policy label. Do not blindly add or replace its label because a tutorial picked that number. A denied bind and a remotely blocked connection fail at different layers and have different owners for the fix.
A malformed protocol selection is possible even after TCP connects. An HTTP client using plain text against a TLS-only listener can receive an error or a closed connection before normal request routing. An HTTPS client on an ordinary plain HTTP socket will fail the TLS setup. Keep the protocol and port fixed when comparing host selection. When the connection is encrypted, preserve the intended name and certificate verification rather than disabling certificate checks. Record both the certificate name presented during connection and the final HTTP body if you need to debug both stages. The local experiment uses plain HTTP with no sensitive contents to avoid combining those features.
| Observation | What to check next | Evidence to save |
|---|---|---|
| Config contains a virtual host for the port, but a local connection fails. | Inspect actual sockets and startup errors. Verify Apache has a matching Listen directive. | The candidate host group and missing or mismatched listener. |
| Loopback gets the correct body, but a permitted remote test times out. | Confirm the intended bind and test path. Check the approved source and applicable routing and network policy. | Separate local and remote destination details and results. |
| The port is already in use. | Identify the socket owner and any wildcard overlap. Choose a free high port for a private fixture. | The exact address, port and observed owning process. |
| The client connects but gets the wrong marker. | Verify the hostname, scheme and application route at the connected endpoint. | Response body and the matching server log. |
| A request through a proxy returns 502. | Test the private endpoint from the proxy's location and check which hop produced the error. | Proxy upstream error plus a direct probe under the expected name and protocol. |
Validate the address from the same network namespace as the relevant service when containers are involved. Each network namespace can have its own loopback interfaces and sockets. Connecting to loopback inside the proxy container normally reaches that container, even when a different container advertises the same port. Inspect the published or private network endpoints explicitly. A container port and a host port may differ on purpose, so annotate both on the worksheet and identify where a connection changes from one address to the other.
On a dual-stack machine, a hostname may resolve to both IPv4 and IPv6 addresses. A direct local comparison using IPv4 only proves that one listener. A client can prefer the other address or try both in a different order. In the lab the destination is fixed to IPv4 loopback, so address-family behavior stays visible in the probe. A production service intended to support both families needs listener and access verification for each, including how the OS treats wildcard binds. A successful connection on one family should not be recorded as evidence about the other.
Choose an access path for a private preview
The practice machine binds to loopback because both clients in the experiment run there. For work across machines, start by naming the parties who should have access. A school's preview might be available from a managed workstation through an authenticated company service. A platform operator might use a managed tunnel from a workstation to a cloud node. A separate web application might be allowed to reach a database on the private network using trusted encryption and application credentials. Each access path can have an appropriate narrow source policy. The mere fact that the software has a common port says nothing about who should be able to connect.
For a managed AWS instance, Systems Manager Session Manager can forward a local port to a managed node through an authorized session. This is an alternative to adding inbound public access to the preview port. It requires that the node is configured for Systems Manager, an appropriately supported agent, caller permissions for the session, and the Session Manager plugin for the CLI workflow. The client connects to a chosen local port while the established session carries the connection to the targeted port on the managed node. The application's own authentication can still matter. The point of the forwarding feature here is to carry traffic along an existing management path.
Suppose a colleague says the managed tunnel is established but the local preview returns an unexpected default. Compare the local and remote port mapping first. The service at the node may have several name-based sites on the forwarded listener. A URL using local loopback as its hostname can carry a different HTTP authority from the intended preview name. The client test should preserve the virtual-host name while resolving it to the local tunnel address when that matches the access design. A port-forwarding session does not change how the virtual server, certificate, and request routing are selected on the other side.
For a conventional reverse proxy, identify where transport ends and starts again. A public HTTPS client connects at the proxy's chosen network address and port. The proxy may speak another HTTP connection to its upstream over loopback or a private network. Check both legs separately if the upstream is unavailable, and keep header forwarding and origin credentials under the service's own policy. Some proxy setups route by hostname, some by path, and some are configured with a specific backend pool. The public client might never see the upstream port. Therefore check the actual upstream endpoint from the proxy rather than expecting public DNS to name it directly.
If a training exercise genuinely requires a direct network path, keep scope limited to the authorized environment. Identify which associated rules collectively permit the port and what source is expected. AWS security groups are stateful, and multiple attached groups can combine allowed paths. Network ACLs are subnet controls and evaluate traffic independently, including the return path. Consider the host firewall only where it applies. Validate the resulting design using permitted and denied test sources without confusing a routable address with trusted user identity. Close any temporary access and return the test environment according to the owner’s process after the exercise. No changes of that kind are needed for the local tests on this page.
Practice with an endpoint table and three outcomes
Write three rows using the lab outputs. First write the server name, scheme, expected local address and port. Next note whether the candidate declares a website for that endpoint and whether a socket is actually listening. Finally note the curl exit status, HTTP status when present and marker if any. For the third row, explain why the parser could list a site and curl could fail within a moment. Ask a colleague to derive the second row without recognizing the web server by a header. They should find the independent marker and correlate its port with the process and actual local destination.
For a test planning exercise, imagine turning the third row into a live local endpoint. Write the exact additional Apache Listen line you would need to match the address already declared for the third port. Identify how to check that the port is free and which candidate would read the new line. In a repeat of the private fixture, test it with the same authority and path. State the marker you expect given its current DocumentRoot. Also repeat the first two requests to show that a new listener can be added without moving another site. Use the optional activation block to restart only its private Apache child. Keep the independent live connection controls and cleanup the same.
For a second worksheet, draw the approved path for an internal preview through a reverse proxy. Label the public or private client address, the first listen port, the downstream address and its port. Mark where TLS and authentication are evaluated. Add a failure branch for an inaccessible upstream and show why opening its port to everyone does not restore the intended route. The completed diagram should let a new operator tell whether a curl check belongs on their workstation, inside the host, or at the proxy. It should also make obvious which service and site's logs to inspect.
Interview questions, quiz and revision cards
Can two services use the same hostname but different destination ports?
Yes. The chosen address and port determine the connection endpoint. The hostname then participates in protocol and site selection as applicable. The lab fixes the address and hostname while the two different ports reach independent web server processes.
Why might an Apache virtual host appear even though its port refuses connections?
The parsed section describes eligible site behavior. Apache opens sockets with Listen. When the address and port have no matching listener, there is no endpoint to accept the connection even though the configuration describes a host for it.
What does a successful loopback request prove about an EC2 security group?
It proves the local listener processed the local request with the observed result. It does not test the inbound path through an instance network interface. Verify the actual bind and the expected remote access route separately if the application should receive remote traffic.
How do you decide whether to open a new port publicly?
Start from who should reach the service. A same-host upstream can often stay on loopback and receive requests from a controlled proxy. A managed forwarding session can be another private access path. If direct access belongs in the approved design, allow only the necessary source and retain the intended application access controls.
Does curl's 000 status indicate the origin sent an unusual HTTP code?
It means curl reported no HTTP status for that transfer. In the lab its exit status of 7 confirms that a TCP connection could not be made to the unused listener. Inspect the transfer exit status and exact destination before deciding why a more complex request failed.
For these checks, keep the destination and transport protocol fixed while interpreting a change in port.
Quick quiz
The same hostname and path return two distinct markers after changing only the port. What distinction did the test exercise?
- Two request destinations on the same address
- Two unrelated DNS names
- Two TLS protocols on one unchanged endpoint
Check the first answer
A. Each explicit port positions the connection at a different listener. The fixed name and path remove two other causes of a different response.
An Apache configuration has only a VirtualHost for the new port and no matching Listen. What should you verify?
- Whether the browser needs an empty cookie
- Whether the intended address and port actually have a listening socket
- Whether the directory contains more than one image
Check the second answer
B. Configuration describing a host does not by itself bind the endpoint. Compare the parser report to the actual socket list and a controlled connect attempt.
The private preview works at loopback. The team will access it by an approved tunnel. Which security-group change is required by this lab?
- Allow everyone to connect directly to the preview port
- Allow direct traffic temporarily from an arbitrary subnet
- No inbound rule for the local preview port is required for this isolated task
Check the third answer
C. The lab is local. A managed connection may require its own documented prerequisites and policies, but the preview does not need direct public ingress just because it listens on a high port.
Address, transport and port
Identify the live endpoint as an address and port under a particular protocol. Read the socket list rather than relying on a filename.
Apache listen and site scope
Listen opens a socket. VirtualHost groups candidate site behavior for an eligible endpoint.
Local versus remote route
Loopback probes prove local behavior. Remote network rules and application authorization are separate checks.
Transport versus HTTP
Connection refusal, timeout, redirect and application denial report different stages. Record curl's process status, HTTP status and body where available.