Disabling keepalive

L
  • 21 Oct '22
Hello,

Is there a way to totally disable keepalive form upstream? Right now, I have
the following configuration in upstream to keep the figures to a minimum-

keepalive: 1;
keepalive_requests: 1;
keepalive_timeout: 1s;
keepalive_time: 1s

Since, I can't change the keepalive directive's value to 0, is there a way I
can remove this setting totally?

Thanks!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,295571,295571#msg-295571
M
  • 21 Oct '22
Hello!

On Fri, Oct 21, 2022 at 11:02:20AM -0400, libresco_27 wrote:

> Is there a way to totally disable keepalive form upstream? Right now, I have
> the following configuration in upstream to keep the figures to a minimum-
> 
> keepalive: 1;
> keepalive_requests: 1;
> keepalive_timeout: 1s;
> keepalive_time: 1s
> 
> Since, I can't change the keepalive directive's value to 0, is there a way I
> can remove this setting totally?

Keepalive connections with upstream servers are disabled by 
default.  That is, it is enough to remove the "keepalive" 
directive from the upstream block to disable connection cache 
completely.

Note that you may also want to adjust proxying configuration to 
ensure connections are closed by the upstream server when 
possible.  In particular, make sure you are not using 
"proxy_set_header Connection "";" with HTTP proxying and/or 
"fastcgi_keep_conn on;" with FastCGI.

See http://nginx.org/r/keepalive for details.

-- 
Maxim Dounin
http://mdounin.ru/
L
  • 28 Oct '22
Thanks for your answer!
I have another query if we can actually see that keepalive is being disabled
in nginx logs. 
Is it possible to confirm that if we run nginx in debug mode and if so, what
kind of logs should I look for?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,295571,295628#msg-295628
M
  • 30 Oct '22
Hello!

On Fri, Oct 28, 2022 at 09:01:27AM -0400, libresco_27 wrote:

> Thanks for your answer!
> I have another query if we can actually see that keepalive is being disabled
> in nginx logs. 
> Is it possible to confirm that if we run nginx in debug mode and if so, what
> kind of logs should I look for?

When keepalive with upstream servers is enabled, in the debug logs 
there will be "get keepalive peer", "get keepalive peer: using 
connection ...", "free keepalive peer", and "free keepalive peer: 
saving connection ..." messages when selecting a peer and 
finalizing upstream request.  For example, a connection attempt 
without a cached connection but with keepalive enabled will look 
like:

2022/10/30 07:18:31 [debug] 13406#100156: *1 http init upstream, client timer: 0
2022/10/30 07:18:31 [debug] 13406#100156: *1 kevent set event: 11: ft:-2 fl:0025
2022/10/30 07:18:31 [debug] 13406#100156: *1 http script copy: "Host"
2022/10/30 07:18:31 [debug] 13406#100156: *1 http script var: "u"
2022/10/30 07:18:31 [debug] 13406#100156: *1 http script copy: "Connection"
2022/10/30 07:18:31 [debug] 13406#100156: *1 http script copy: "close"
2022/10/30 07:18:31 [debug] 13406#100156: *1 http script copy: ""
2022/10/30 07:18:31 [debug] 13406#100156: *1 http script copy: ""
2022/10/30 07:18:31 [debug] 13406#100156: *1 http proxy header:
"GET / HTTP/1.0
Host: u
Connection: close

"
2022/10/30 07:18:31 [debug] 13406#100156: *1 http cleanup add: 21982D88
2022/10/30 07:18:31 [debug] 13406#100156: *1 init keepalive peer
2022/10/30 07:18:31 [debug] 13406#100156: *1 get keepalive peer
2022/10/30 07:18:31 [debug] 13406#100156: *1 get rr peer, try: 1
2022/10/30 07:18:31 [debug] 13406#100156: *1 stream socket 12
2022/10/30 07:18:31 [debug] 13406#100156: *1 connect to 127.0.0.1:8081, fd:12 #2
2022/10/30 07:18:31 [debug] 13406#100156: *1 kevent set event: 12: ft:-1 fl:0025
2022/10/30 07:18:31 [debug] 13406#100156: *1 connected

Without keepalive enabled there will be no "init keepalive peer" 
and "get keepalive peer" messages:

2022/10/30 07:21:36 [debug] 13416#100132: *1 http init upstream, client timer: 0
2022/10/30 07:21:36 [debug] 13416#100132: *1 kevent set event: 11: ft:-2 fl:0025
2022/10/30 07:21:36 [debug] 13416#100132: *1 http script copy: "Host"
2022/10/30 07:21:36 [debug] 13416#100132: *1 http script var: "u"
2022/10/30 07:21:36 [debug] 13416#100132: *1 http script copy: "Connection"
2022/10/30 07:21:36 [debug] 13416#100132: *1 http script copy: "close"
2022/10/30 07:21:36 [debug] 13416#100132: *1 http script copy: ""
2022/10/30 07:21:36 [debug] 13416#100132: *1 http script copy: ""
2022/10/30 07:21:36 [debug] 13416#100132: *1 http proxy header:
"GET / HTTP/1.0
Host: u
Connection: close

"
2022/10/30 07:21:36 [debug] 13416#100132: *1 http cleanup add: 21982D88
2022/10/30 07:21:36 [debug] 13416#100132: *1 get rr peer, try: 1
2022/10/30 07:21:36 [debug] 13416#100132: *1 stream socket 12
2022/10/30 07:21:36 [debug] 13416#100132: *1 connect to 127.0.0.1:8081, fd:12 #2
2022/10/30 07:21:36 [debug] 13416#100132: *1 kevent set event: 12: ft:-1 fl:0025
2022/10/30 07:21:36 [debug] 13416#100132: *1 connected

Hope this helps.

-- 
Maxim Dounin
http://mdounin.ru/
L
  • 16 Nov '22
Thank you so much for your help!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,295571,295776#msg-295776