Atlaslog
Atlaslog / Field Notes / Services & tile access
Field note · Services & tile access

WMS keeps returning 502 while the service is still alive

Quick answer

GeoServer on port 8080 answers fine directly, but through Nginx a 2048x2048 GetMap returns 502 Bad Gateway and occasionally succeeds. Rendering that tile takes tens of seconds, beyond the default 60-second upstream read timeout.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Nginx 1.24 · GeoServer 2.25
Symptom
Checklist
  1. curl the same GetMap against 127.0.0.1:8080 and record http_code and time_total.
  2. Check whether the elapsed time approaches 60 seconds.
  3. Classify the nginx error log entry as prematurely closed, timed out or connection refused.
  4. Check catalina.out and geoserver.log for OutOfMemoryError or render failures.
  5. Check buffering limits if the log reports upstream sent too big header.
Fix

In a location dedicated to /geoserver/wms raise proxy_read_timeout and proxy_send_timeout to 120s and set proxy_buffer_size 16k with proxy_buffers 8 64k; cap image cost with maxRequestMemory=65536 in KB and maxRenderingTime=60. Serve large extents as 512-pixel TileWMS requests with TILED true.

Code
502 Bad Gateway
nginx/1.24.0
2026/10/29 10:12:44 [error] 1842#1842: *31 upstream prematurely closed connection
while reading response header from upstream, client: 10.0.2.18,
request: "GET /geoserver/wms?SERVICE=WMS&REQUEST=GetMap&LAYERS=roads&WIDTH=2048&HEIGHT=2048 HTTP/1.1",
upstream: "http://127.0.0.1:8080/geoserver/wms?...", host: "gis.example.cn"
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). WMS keeps returning 502 while the service is still alive. https://www.jingweizhi.com/en/cookbook/wms-502-bad-gateway.html (accessed 2026-11-03).