Reverse proxy
Обратный прокси
A reverse proxy sits in front of one or more application servers. It accepts requests at the address clients know, passes them to the appropriate server, and sends the response back.
What a reverse proxy does
Suppose a browser requests shop.example/api/items. It connects to the reverse proxy at shop.example, not directly to the inventory service. The proxy knows where that service is running and forwards the request. The application server is often called an upstream or a backend. You can move it to a new host without asking users to change the URL.
What happens to a request
For HTTP traffic, the proxy can choose a backend based on the hostname or path. It sends the request over a separate connection to that backend, often reusing an existing connection, and relays the response to the client. If caching is enabled and the proxy has a fresh response it can reuse, it can answer without contacting the backend.
A common setup is TLS termination: the proxy presents the site's certificate and decrypts the browser's HTTPS traffic. That gives an HTTP-aware proxy access to details such as the request path. The connection from the proxy to the application is configured independently; terminating TLS at the proxy does not rule out using HTTPS on the backend connection too.
Example: route API traffic with Nginx
This location block goes inside a server block. It sends requests under /api/ to an application listening locally on port 8080:
location /api/ {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}
A request for /api/items reaches the app as /api/items: the proxy_pass target has no URI part to replace the matching prefix. The app can use X-Forwarded-Proto to generate HTTPS redirects even when the Nginx-to-app connection uses HTTP. It should only honor forwarding headers from trusted proxies, and the public-facing proxy should set or sanitize the values it passes on.
Where it fits
Teams use reverse proxies to serve multiple apps from a single hostname, manage certificates at the edge, or apply shared rate limits. A reverse proxy can also balance requests across replicas, but it can sit in front of just one app. A forward proxy serves the opposite side of the interaction: clients use it to reach destination servers, whereas a reverse proxy receives traffic on behalf of the servers behind it. Putting a proxy in front of an app does not, by itself, block direct access to the app; network access controls handle that separately.
What interviewers look for
Trace the client-to-proxy and proxy-to-app connections separately. If the proxy generated a 502 Bad Gateway, it could not obtain a usable response from the upstream, for example because the connection was refused. A proxy-generated 504 Gateway Timeout points to an upstream time limit being exceeded. Check the proxy logs first to establish whether it generated the status or simply relayed it, then compare upstream connection and response timings.