this post was submitted on 04 Dec 2024
1 points (100.0% liked)

nginx

4 readers
1 users here now

The nginx community on Reddit. Reddit gives you the best of the internet in one place.

founded 1 year ago
MODERATORS
 
The original post: /r/nginx by /u/yegor-usoltsev on 2024-12-04 11:20:20.

Hi all,

I've been experimenting with HTTP keep-alive in NGINX as a reverse proxy and documented my findings in this GitHub repo.

The one thing that caught my attention is that NGINX does require additional configuration in order for it to reuse upstream connections, unlike other proxies such as HAProxy, Traefik, or Caddy, which all enable HTTP keep-alive by default. So here's my final configuration that came out of this:

server {
    location / {
        proxy_pass http://backend/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    "" "";
}

upstream backend {
    server 127.0.0.1:8080;
    keepalive 16;
}

To the community:

  1. Why keep-alive isn't enabled by default in NGINX?
  2. Are there any edge cases I might have overlooked?
  3. What would you suggest for simplifying or improving those configurations?

Looking forward to hearing your thoughts!

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here