Plainnotes

Upstream keepalive that made things slower

2026-01-21 · 2 min readDeploy

Adding keepalive 32 to an upstream did not raise throughput; timeouts went up. Usually two other settings are missing.

upstream app {
    server 127.0.0.1:8080;
    keepalive 32;
}
server {
    location / {
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_pass http://app;
    }
}

With HTTP/1.0 to the upstream, connections are never reused. Without clearing Connection, nginx forwards the client's close and every request opens a new socket.

Also make sure upstream's keepalive_timeout is longer than nginx's; otherwise nginx holds sockets the server already closed and requests fail outright.