Skip to main content
Infrastructure

Nginx

The useful decision is what happens at the web boundary.

The application works on its own port. Production still needs to decide which requests reach it, how HTTPS ends, whose IP address is trusted and what happens when the upstream is slow.

Nginx can serve static files, terminate TLS, reverse-proxy applications, balance traffic and apply request controls at that boundary. It is dependable when its job is narrow and its configuration is treated as production code. It becomes difficult when years of redirects, exceptions and copied snippets accumulate without an owner.

We choose Nginx by mapping the request path rather than by assuming every Linux server needs it.

Nginx should have a named job at the request boundary

For a conventional Laravel, PHP or Node application, Nginx often listens on the public ports and passes dynamic work to an application process. It may serve versioned assets directly and redirect HTTP to HTTPS. That is enough for many systems.

Adding load balancing, page caching, rate limits or complex routing can be valid, but each feature makes Nginx part of application behaviour. A route that changes upstream based on a cookie is no longer neutral plumbing. It needs the same review and testing as code.

We document the path from DNS to Nginx and from Nginx to every upstream. The diagram records ports, encryption, health assumptions and the system responsible for the response. If a CDN or managed load balancer already performs the public boundary job, another proxy needs a clear purpose.

Proxy headers define identity and protocol

The upstream needs to know the original host, scheme and client address for redirects, secure cookies, logging and abuse controls. Nginx’s proxy module allows those headers to be set, but the correct values depend on the proxies in front of it.

Blindly trusting X-Forwarded-For from the public internet lets a client claim another address. Trust should begin only at a known proxy, with Nginx or the application configured for the actual chain. The same care applies to X-Forwarded-Proto: a wrong scheme can produce redirect loops or cookies without the expected security attribute.

WebSockets and streaming responses add connection and buffering behaviour. We test them through the whole route, not against the application port alone.

TLS termination creates certificate and policy ownership

Nginx can terminate HTTPS and forward to a local application. That centralises certificates and lets the application focus on HTTP, provided the internal hop and host threat model justify it.

The configuration needs current protocols, certificate chains, renewal and a safe failure signal. Mozilla’s TLS configuration guidance is a useful independent starting point for modern compatibility profiles. It still needs adapting to the site’s users and Nginx build.

Certificate automation is incomplete until renewal has been observed and the running Nginx process receives the new material. We monitor expiry externally. A successful renewal log does not prove the certificate served to customers changed.

When Cloudflare or a load balancer terminates public TLS, the origin connection still needs an explicit mode. Encrypting to the origin and verifying the expected certificate avoids turning the provider-to-server hop into an unexamined gap.

Nginx caching needs an invalidation and privacy model

Static assets with content-hashed filenames are straightforward to cache for a long time. Dynamic HTML, account pages and API responses are different. Nginx can cache upstream responses, but cookies, authorisation, language, query strings and application cache headers affect whether one response is safe for another customer.

We begin with assets and only cache dynamic responses when the route has a clear key, bypass and purge story. The proxy caching documentation exposes substantial control; that power makes an undocumented example dangerous.

A cache-hit header in staging helps prove behaviour. Tests cover signed-in users, preview content, errors and a release that changes a page. Purging everything on every deployment may be acceptable at modest scale, but it should be a conscious policy.

Timeouts and buffering express failure policy

Copied timeout values often hide a slow application rather than protect customers. Connection, read and send timeouts apply at different stages. A report that legitimately takes minutes and a normal page request should not inherit the same tolerance.

Nginx buffering can shield a slow client from an upstream and improve throughput. It can also delay streaming events or consume temporary storage for large responses. Upload size limits, body buffering and upstream timeouts need representative requests.

We decide what the customer should receive when an upstream is unavailable and preserve a request identifier across the boundary. A styled error page is useful, but monitoring must still distinguish a deliberate rejection, an Nginx failure and an application failure.

Configuration changes should fail before reaching traffic

Nginx provides -t to test syntax and referenced files, and its reload starts workers with the new configuration while old workers finish existing connections. The official command-line guide makes both behaviours explicit.

We keep configuration in version control, render environment values without storing secrets and test before every reload. A deployment check then requests a route through Nginx and verifies the expected upstream, redirect and security headers.

Graceful reload does not make every change safe. Removing an upstream, changing a cache key or tightening a body limit can affect live customers immediately. High-risk boundary changes deserve staged traffic or a fast rollback.

Logs need rotation, retention and fields that match diagnosis: request ID, upstream address, upstream response time, status, host and cache result where relevant. Credentials and sensitive query values do not belong there.

Questions to settle before putting Nginx in front

  • “Which exact jobs belong at this boundary?” Keep proxy, TLS, assets and controls explicit.
  • “Which proxies are trusted to state the client IP and scheme?” Configure the real chain.
  • “Which routes stream, upload or run for longer?” Give exceptions evidence and limits.
  • “What may be cached, and what makes a response private?” Test identity and invalidation.
  • “Where does TLS end, and how is renewal proved?” Monitor the customer-facing certificate.
  • “How is configuration tested and rolled back?” Put it through the release process.
  • “Can logs identify the failed upstream request?” Preserve correlation without leaking data.

When Nginx is a sound web boundary

Choose Nginx for a controlled Linux web stack that needs a clear reverse proxy, TLS termination, static delivery or modest traffic distribution. It is mature, efficient and widely understood when the configuration remains small enough to reason about.

The case is strongest when one team owns the configuration alongside the application and monitoring. Request-path tests and automated config validation keep the boundary from drifting.

When another layer should own the job

Use a managed load balancer when automatic service discovery, regional resilience and provider integration matter more than direct proxy control. Avoid keeping Nginx solely because an old deployment recipe included it.

Caddy can be the smaller self-managed option when straightforward HTTPS automation and proxying cover the requirement. Apache may remain the sensible choice in an estate whose modules, hosting and operators already depend on it.

And do not build a private application language inside Nginx configuration. Authentication rules, complex experiments and domain routing are often easier to test and observe in the application or a purpose-built edge service.

Alexander De Sousa, Founder of Digital Royalty
Developer’s verdict

Give Nginx a small, explicit boundary job and test it like application code.

I use Nginx when I can draw the request path and explain every responsibility at the boundary. I want trusted proxy headers, TLS renewal, timeout policy and a tested reload in the same production plan. If the configuration has become an undocumented routing language, I simplify it before adding another rule.

Alexander De Sousa · Founder, Digital Royalty · LinkedIn

Decision evidence

What Nginx changes between the customer and the application

Nginx can provide a precise, efficient web boundary. Its headers, TLS, cache and failure settings become part of customer-visible application behaviour.

The Nginx commitment in six decisions

Best fit
Self-managed web stacks needing reverse proxying, TLS, static delivery or controlled traffic distribution in front of known applications.
Customer effect
Fast, consistent request handling when routes are clear; loops, stale content or shared failures when proxy and cache rules are wrong.
Adoption cost
Low for a simple virtual host and proxy, increasing with multi-upstream routing, cache policy, WAF-style rules and several layers of forwarding.
Ongoing owner
An infrastructure or application team responsible for configuration, packages, certificates, access logs, upstream health and release validation.
Exit cost
Low for conventional proxy and TLS settings; higher when application routing and cache behaviour have moved into extensive Nginx rules.
Proof required
Tests for redirects, client identity, TLS, the longest request, cache isolation, upstream failure and a configuration reload.

Boundary options to compare before installing Nginx

  • Nginx on the application hosts

    Right when: A conventional Linux service needs a direct, controllable HTTP boundary close to its application processes.

    Watch for: Keep repeated host configuration automated and avoid making each server a slightly different production snowflake.

  • Managed cloud load balancer

    Right when: Provider-managed health checks, certificates, service scaling and multi-zone traffic are worth accepting the platform model and cost.

    Watch for: Header trust, timeouts, logging and origin protection remain design decisions.

  • Caddy

    Right when: A smaller self-managed deployment values automatic HTTPS and straightforward reverse proxy configuration.

    Watch for: Check module, policy and team familiarity requirements before changing an established boundary for configuration brevity.

  • Keep an established Apache boundary

    Right when: Existing hosting, modules and operator knowledge already meet the service's security and performance requirements.

    Watch for: Confirm the estate is maintained and measured rather than replacing or retaining it on reputation alone.

Research behind this Nginx position

  • Official introduction
    Nginx beginner's guide

    Describes the master and worker model, static serving, proxying and configuration reload that underpin a conventional Nginx boundary.

  • Official proxy reference
    Nginx HTTP proxy module

    Documents header, buffering, timeout and cache controls whose values affect application identity, streaming and failure behaviour.

  • Official operations
    Nginx command-line parameters

    Provides configuration testing and graceful reload controls suitable for an automated release gate.

  • Official traffic distribution
    Using Nginx as an HTTP load balancer

    Covers upstream groups and distribution methods, showing that balancing policy becomes an explicit part of the request route.

  • Independent TLS guidance
    Mozilla SSL Configuration Generator

    Supplies current compatibility profiles for Nginx and other servers; the chosen profile still needs matching to customer and certificate requirements.

  • Official rate controls
    Nginx request-rate limiting

    Shows zone, burst and delay controls. Limits require route-specific testing to avoid rejecting legitimate customers or automation.

  • Practitioner diagnosis
    Stack Overflow: preserving client IP through Nginx

    The recurring question illustrates how proxy chains obscure identity. Trust settings should follow the current official real-IP documentation.

  • Community cache experience
    Reddit: diagnosing CDN and origin caching

    Practitioners describe unexpected misses and layered cache behaviour. It is anecdotal context for testing headers and bypasses across the whole request path.

Get started

Tell us what you need

A few quick questions, then a straight answer from a real person — usually within a few hours.

Tell us what you're working on

Whether it's a new site, a platform, or a process that shouldn't be manual any more — we'll tell you honestly if we can help.