How to make nginx establish persistent connections with squid?

hi,
I use nginx as load balance and forward request to squid use http/1.1,
the
topology is below:

chrome —> nginx(:80) —> squid(:8080) —> origin server(nginx :80)

the nginx configuration:
upstream backend {
server 192.168.13.210:80;
keepalive 10;
}

server {
listen 80 default;
server_name _;

proxy_set_header  Host  $host;

proxy_http_version 1.1;
proxy_set_header Connection "";

location / {
    proxy_pass http://backend;
}

}

the squid configuration of persistent connections is supported on both
client side and server side:
##########timeout##########
client_persistent_connections on
server_persistent_connections on

request_timeout 240 seconds #to client/wait client’s request
client_lifetime 240 seconds #to client/all request time
persistent_request_timeout 30 seconds #to client/keepalive
pconn_timeout 30 seconds #to origin server or peer/keepalive
connect_timeout 240 seconds #to origin server/only connect
read_timeout 240 seconds #to origin server or peer/wait recv data

Then, I made 5 requests such as
http://test.cache.com/p3.jpg?tt=2013032206
and could not find any persistent connection between nginx and squid.

the squid log show:
127.0.0.1 - - [22/Mar/2013:16:12:06 +0800] “GET
http://test.cache.com/p3.jpg?tt=2013032205 HTTP/1.1” 304 364
http://test.cache.com/p3.jpg?tt=2013032205” “Mozilla/5.0 (Windows NT
6.1)
AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172
Safari/537.22”
TCP_REFRESH_HIT:DIRECT/192.168.13.210 0

“Host: test.cache.com #request header
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like
Gecko) Chrome/25.0.1364.172 Safari/537.22
Referer: http://test.cache.com/p3.jpg?tt=2013032205
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
If-Modified-Since: Tue, 23 Oct 2012 04:07:19 GMT”

“HTTP/1.0 304 Not Modified #response header
Server: nginx/1.2.6
Date: Fri, 22 Mar 2013 08:12:06 GMT
Last-Modified: Tue, 23 Oct 2012 04:07:19 GMT
Expires: Fri, 22 Mar 2013 10:12:06 GMT
Cache-Control: max-age=7200
X-Cache: MISS from vm-linux1.test.com
X-Cache-Lookup: HIT from vm-linux1.test.com:8080
Via: 1.1 vm-linux1.test.com:8080 (squid/2.7.STABLE9)
Connection: close”

as we see(last line), squid announced the Connection should be close
after
the request. I think this is why nginx couldn’t make a persistent
connection
with squid.

then I try to set: proxy_set_header Connection “keep-alive”; forcing
that
the request must be keep-alive.
the request and response is:

127.0.0.1 - - [22/Mar/2013:15:59:09 +0800] “GET
http://test.cache.com/p3.jpg?tt=2013032203 HTTP/1.1” 304 369
http://test.cache.com/p3.jpg?tt=2013032203” “Mozilla/5.0 (Windows NT
6.1)
AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172
Safari/537.22”
TCP_REFRESH_HIT:DIRECT/192.168.13.210 0

“Host: test.cache.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like
Gecko) Chrome/25.0.1364.172 Safari/537.22
Referer: http://test.cache.com/p3.jpg?tt=2013032203
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
If-Modified-Since: Tue, 23 Oct 2012 04:07:19 GMT”

“HTTP/1.0 304 Not Modified
Server: nginx/1.2.6
Date: Fri, 22 Mar 2013 07:59:09 GMT
Last-Modified: Tue, 23 Oct 2012 04:07:19 GMT
Expires: Fri, 22 Mar 2013 09:59:09 GMT
Cache-Control: max-age=7200
X-Cache: MISS from vm-linux1.test.com
X-Cache-Lookup: HIT from vm-linux1.test.com:8080
Via: 1.1 vm-linux1.test.com:8080 (squid/2.7.STABLE9)
Connection: keep-alive”

though the Connection of response is keep-alive, nginx still didn’t make
any
persistent connection with squid.

Is there any way to configure nginx use a persistent connection where
forward requests to squid ? help help

nginx_version: 1.2.6
squid_version: 2.7.STABLE9

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,237666,237666#msg-237666

Hello!

On Fri, Mar 22, 2013 at 05:25:15AM -0400, selphon wrote:

}

the squid log show:
Gecko) Chrome/25.0.1364.172 Safari/537.22
Expires: Fri, 22 Mar 2013 10:12:06 GMT
then I try to set: proxy_set_header Connection “keep-alive”; forcing that
Connection: keep-alive
"HTTP/1.0 304 Not Modified
though the Connection of response is keep-alive, nginx still didn’t make any
persistent connection with squid.

Is there any way to configure nginx use a persistent connection where
forward requests to squid ? help help

nginx_version: 1.2.6
squid_version: 2.7.STABLE9

Connections are kept alive only if a response is in HTTP/1.1
protocol.


Maxim D.
http://nginx.org/en/donation.html

Thank you, Maxim D…

I see.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,237666,237713#msg-237713

Hello!

On Sun, Mar 24, 2013 at 04:42:36AM -0400, selphon wrote:

[…]

Though the response is in HTTP/1.0, the persistent connections is
successfully established between chrome and squid. I wonder, is there a
restriction that nginx can only make establish persistent connections when
the response is in HTTP/1.1 protocol ?

It looks I wasn’t clear enough. While keepalive connections via
HTTP/1.0 are possible with “Connection: keep-alive” extension,
nginx will only keep upstream connections alive after an HTTP/1.1
response.


Maxim D.
http://nginx.org/en/donation.html

Hi, Maxim D.

I revise the topology:
chrome --> squid:80 --> origin server(nginx :80)

and make 5 requests,the squid log shows:

192.168.70.160 - - [22/Mar/2013:15:41:41 +0800] “GET
http://test.cache.com/p3.jpg?tt=2013032201 HTTP/1.1” 304 365
http://test.cache.com/p3.jpg?tt=2013032201” “Mozilla/5.0 (Windows NT
6.1)
AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172
Safari/537.22”
TCP_REFRESH_HIT:DIRECT/192.168.13.210 0

“Host: test.cache.com #request header
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like
Gecko) Chrome/25.0.1364.172 Safari/537.22
Referer: http://test.cache.com/p3.jpg?tt=2013032201
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
If-Modified-Since: Tue, 23 Oct 2012 04:07:19 GMT”

“HTTP/1.0 304 Not Modified #response header
Server: nginx/1.2.6
Date: Fri, 22 Mar 2013 07:41:41 GMT
Last-Modified: Tue, 23 Oct 2012 04:07:19 GMT
Expires: Fri, 22 Mar 2013 09:41:41 GMT
Cache-Control: max-age=7200
X-Cache: MISS from vm-linux1.test.com
X-Cache-Lookup: HIT from vm-linux1.test.com:80
Via: 1.1 vm-linux1.test.com:80 (squid/2.7.STABLE9)
Connection: keep-alive”

Though the response is in HTTP/1.0, the persistent connections is
successfully established between chrome and squid. I wonder, is there a
restriction that nginx can only make establish persistent connections
when
the response is in HTTP/1.1 protocol ?
Thx for answering.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,237666,237714#msg-237714

Upgrade to >= squid 3.2, which seems to support HTTP/1.1 and you
will have your persistent connections with squid:

http://www.squid-cache.org/mail-archive/squid-users/201108/0061.html
http://wiki.squid-cache.org/Squid-3.2

Thank you~
As the test show, squid can make keepalive connections base on HTTP/1.0,
it
is a character of squid 2.7.9.
Unfortunately, nginx can not make keepalive connections with squid
2.7.9, I
think.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,237666,237869#msg-237869

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs