Working with Nginx?

Nginx throwing 502 or 504? We fix it.

Nginx usually gets blamed for errors that start somewhere behind it, in an app server that hung or a timeout set too short. We read the config and the logs together, then put the fix where it actually belongs.

  • Since 2015Fixing technology
  • FreeEstimates
  • US teamReal engineers

error.log

still failing

What it is

Nginx at a glance

Nginx, pronounced engine x, is an open-source web server first released by Igor Sysoev in 2004 to solve what people called the C10K problem at Rambler: handling ten thousand simultaneous connections on one machine. It is published under the two-clause BSD licence, which lets anyone run or modify it at no cost.

Today it does far more than serve pages. It sits in front of application servers written in PHP, Node, Python or Ruby, terminates TLS, caches responses, balances load between backends and shields them from the open internet. By one measurement, from W3Techs, it now fronts more than thirty percent of the sites on the web. NGINX, Inc. was acquired by F5 Networks in 2019.

Type
Web server and reverse proxy
First released
2004
License
Two-clause BSD, free and permissive
Maintained by
NGINX, Inc. (part of F5 Networks) with outside contributors
Typically used for
HTTP front end, reverse proxy, SSL termination, static file serving, load balancing, rate limiting

The honest version

Nginx pros and cons

No technology is all upside. This is where Nginx earns its place and where it tends to cause trouble.

Where Nginx is strong

  • Light on the machineThe event-driven worker model handles thousands of connections per process without a thread per request, so it holds up under load on modest hardware.
  • The default reverse proxyAlmost every modern stack assumes something like nginx is out front, which means examples, modules and hosting images are easy to come by.
  • Readable configurationThe main config file uses nested blocks that most engineers can follow without a manual once they know where the semicolons go.
  • Modern protocol supportHTTP/2 and HTTP/3 are built in, along with a response cache and request rate limiting, so a lot of what used to need a separate box lives in one process.
  • Offloads work from the backendServing static files, terminating TLS and caching answers at the edge keeps the application server free to do the parts only it can do.

Where Nginx bites

  • The config is strict in odd placesA missing semicolon stops a reload cold, while a quietly wrong proxy_pass trailing slash changes routing in ways that look fine until a page breaks.
  • Location matching trips people upPrefix, regex and exact matches follow rules that are not the order they appear in the file, so copy-pasted blocks sometimes catch requests nobody meant them to.
  • Inherited configs no-one reviewsMany sites run an nginx.conf that was handed down across three agencies, full of commented-out blocks and settings that stopped being relevant years ago.
  • Observability needs work up frontAccess and error logs are useful but plain, and turning them into dashboards or alerts means wiring up a log pipeline before you need it.
  • The free build stops short of some featuresActive health checks, a live dashboard and some session persistence features sit behind the commercial NGINX Plus subscription.
  • No .htaccess-style per-directory module systemDynamic modules exist, but there is no equivalent of dropping a file into a folder to change behaviour the way Apache allows.

Sound familiar?

Common Nginx problems we fix

The Nginx problems that bring people to us, and what you have once each one is fixed.

upstream refused · 502

Nginx returns 502 Bad Gateway

The backend behind the proxy is down, bound to the wrong socket, or killed by its own error before it could answer. Nginx reports what it saw at the door, not what caused it.

Proxy and backend aligned

504 Gateway Time-out

Long requests get cut off with 504

The upstream is still working when proxy_read_timeout expires. Raising it blindly hides the real cost of the request; tuning it alongside the app's own timeouts lets slow pages finish cleanly.

Timeouts matched end to end

client intended to send too large body

File uploads fail part-way through

The default client_max_body_size is one megabyte, and most people only find that out when a customer tries to attach a photo. Raising it has to happen in the right server or location block to take effect.

Uploads sized for real files

SSL handshake failure

HTTPS works for some clients and not others

An old protocol version left enabled, a missing intermediate certificate, or a cipher list that excluded a platform the business still supports.

TLS tested across real clients

configuration test failed

A reload took the site down

Someone edited nginx.conf, ran systemctl reload, and only then found out the test had never passed. A pre-reload check and a known-good backup make this a non-event.

Safe reloads every time

limit_req zone 'one' exhausted

Rate limiting blocks real customers

A zone copied from a tutorial applies the same limit to a login form and to an API that polls every second. Legitimate traffic trips the limiter before any attacker does.

Limits that fit your traffic

no 'ssl_certificate' is defined

The certificate renewal left the site serving plain HTTP

A certbot run that produced new files but never reloaded nginx, or a server block listening on 443 without the ssl_certificate directive it needs.

Renewals that reload cleanly

handed over without notes

Nobody understands the current config

A previous team left a maze of includes, maps and upstream groups with no comments and no diagram. Changing anything feels like defusing a bomb.

Config documented and tidied

What we do

Nginx help, from rescue to upkeep

Call us for one 502, or hand us the whole front end.

Rescue
Front end down, returning 502 or 504 across the board, or failing to reload. We get traffic flowing, then find out what broke it.
Reverse proxy and SSL
Routing to the right backend, matching timeouts, buffering and headers, with certificates that renew without a person watching.
Performance and caching
Response caching, HTTP/2 and HTTP/3 tuning, worker and connection limits set to the hardware you actually have.
Hardening
Rate limiting, sensible headers, locking down admin paths and keeping the config auditable rather than copied from the internet.
Migrations
Moving off Apache, IIS or a cloud load balancer onto an nginx front end, without changing URLs out from under search engines.
Managed Tech
Monitoring, renewals, config changes and a team to call, on an ongoing basis.

How it works

From first message to fixed

  1. Look Free estimate

    Tell us what's going wrong. We look at it, then tell you plainly what's wrong and what it will cost.

  2. Fix

    We fix the cause, not the symptom. If something is down, getting it back up comes first.

  3. Harden

    Backups, monitoring, updates and access, so the same problem can't quietly come back.

  4. Hand back or stay on

    You get a plain-language write-up. Or we stay on for hosting, upkeep and new work.

Often found together

Running Nginx alongside something else?

We work on the whole stack, so the problem can be wherever it actually is.

Questions

Nginx questions

Something else? Call+1 737 727 7327

Why are we getting 502 Bad Gateway from nginx?

A 502 means nginx tried to reach the upstream and got refused, reset or a reply it could not parse. The usual causes are an application server that crashed, one listening on a different socket than the proxy_pass line expects, or a container that restarted and came up slower than nginx waited. The fix lives in the backend most of the time, not in nginx itself.

Why do large file uploads fail through nginx?

The default client_max_body_size is one megabyte, and anything larger is rejected before it reaches the application. Raising it in the correct server or location block, and matching any limits downstream such as PHP's upload_max_filesize, lets real files through without opening the door to anything.

Can you take over nginx configuration from a previous team?

Yes. We read what is there, map out every include and upstream, note what each block is meant to do, and then propose a tidier version that behaves the same before we switch anything over. Nothing changes in production until the replacement has been tested against your real traffic patterns.

How do we add rate limiting without breaking legitimate traffic?

We look at real request logs first, work out what normal looks like for each path, and then set zones per route rather than one blanket limit. Login endpoints, APIs and page views each get a figure that fits them, and the limits log before they block so we can tune without surprising users.

Should we move from Apache to nginx?

Sometimes. Nginx is lighter under load and friendlier as a reverse proxy, but if a site depends on .htaccess files written over many years, the move costs more than it saves. We look at what Apache is actually doing for you before recommending either way.

How much does Nginx help cost?

Estimates are free. Tell us what the front end is doing and you get a price before any work starts.

Free estimate

Nginx giving you trouble?

Tell us what you're running and what's going wrong. A person reads it and comes back with an estimate.

  • No charge to find out what it will take
  • If it's urgent, say so

Replies come from a person. By sending, you authorize us to email you back. No marketing.