# Help with Keepalive on NGINX

**URL:** <https://www.ruby-forum.com/t/help-with-keepalive-on-nginx/235964>\
**Category:** NGINX\
**Created:** [July 26, 2013, 11:34am UTC](https://www.ruby-forum.com/t/help-with-keepalive-on-nginx/235964 "2013-07-26T11:34:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [July 26, 2013, 11:34am UTC](https://www.ruby-forum.com/t/help-with-keepalive-on-nginx/235964/1 "2013-07-26T11:34:28Z")

</div>

Hi All,

I am struggling to get keepalives to work on Nginx, I believe I have  
added the necessary configuration. Can you take a look and suggest where  
I may be going wrong or what I am missing?

We have a nginx server that sits in front of a varnish server which sits  
in front of the back-end servers

http {

```
 keepalive_timeout 120;
 keepalive_requests 500;

 upstream varnish_rand {
     server 172.21.1.1:80;
     keepalive 256;
 }

 server {
     server_name www.abc.com

     location / {

         proxy_pass http://varnish_rand;
         proxy_http_version 1.1;

         }

```

}

You can see that the nginx server is using HTTP1.1 to communicate with  
Varnish

\*varnishtop -i RxProtocol \*  
list length 1

```
  9.67 RxProtocol HTTP/1.1

```

However there nginx always send a “connection close”

_varnishtop -c -i RxHeader -I “Connection”_

list length 1

```
  9.59 RxHeader Connection: close

```

Thanks in advance

Nick

---

<div class="post-metadata">

**Author:** ![ntran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/73ab20/32.png) [@ntran](https://www.ruby-forum.com/u/ntran)\
**Post date:** [July 26, 2013, 12:03pm UTC](https://www.ruby-forum.com/t/help-with-keepalive-on-nginx/235964/2 "2013-07-26T12:03:41Z")

</div>

Hello!

On Fri, Jul 26, 2013 at 10:33:42AM +0100, Nick T. wrote:

> ```
> 9.59 RxHeader Connection: close
> 
> ```

That’s because nginx uses “Connection: close” by default,  
regardless of a protocol version used. If you want keepalive to  
work, you have to instruct nginx to don’t send “Connection:  
close” using the proxy\_set\_header directive.

For more information see documentation at  
[Module ngx\_http\_upstream\_module](http://nginx.org/r/keepalive).

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![ntran](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/73ab20/32.png) [@ntran](https://www.ruby-forum.com/u/ntran)\
**Post date:** [July 26, 2013, 3:55pm UTC](https://www.ruby-forum.com/t/help-with-keepalive-on-nginx/235964/3 "2013-07-26T15:55:36Z")

</div>

Hi Maxim,

Thanks for the reply, a great help. works as expected now 🙂

Have a good weekend

Cheers

Nick
