# How do I set Keep Alive

**URL:** <https://www.ruby-forum.com/t/how-do-i-set-keep-alive/244236>\
**Category:** NGINX\
**Created:** [March 9, 2016, 8:15am UTC](https://www.ruby-forum.com/t/how-do-i-set-keep-alive/244236 "2016-03-09T08:15:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [March 9, 2016, 8:15am UTC](https://www.ruby-forum.com/t/how-do-i-set-keep-alive/244236/1 "2016-03-09T08:15:53Z")

</div>

Hello, I am new to nginx and Speedgrade suggest I enable keepalive to  
enhance performance of my website(s).

I’ve read\*1 that enabling this is also a risk. What is the best  
practise?

\*1 [Using NGINX as an Accelerating Proxy for HTTP Servers](https://www.nginx.com/blog/http-keepalives-and-web-performance/)

Posted at Nginx Forum:

> **[How do I set Keep Alive](https://forum.nginx.org/read.php?2,265177,265177#msg-265177)**
>
> Hello, I am new to nginx and Speedgrade suggest I enable keepalive to enhance performance of my website(s). I've read\*1 that enabling this is also a risk. What is the best practise? \*1 https://www.nginx.com/blog/http-keepalives-and-web-performance/

---

<div class="post-metadata">

**Author:** ![RemcoJanssen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@RemcoJanssen](https://www.ruby-forum.com/u/RemcoJanssen)\
**Post date:** [March 9, 2016, 2:49pm UTC](https://www.ruby-forum.com/t/how-do-i-set-keep-alive/244236/2 "2016-03-09T14:49:02Z")

</div>

If your backend is sensitive to keepalive traffic (mine are), then my  
advice is to enable keepalives as far into your stack as you can.

i.e. I have nginx fronting haproxy and varnish, I enable keepalives to  
both  
haproxy and varnish add have them add a “connection: close” header to  
their  
backend requests. That keeps the backends happy but still lets the  
frontends take advantage of connection reuse.

On Wed, Mar 9, 2016 at 2:15 AM, RemcoJanssen  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
