HTTP 1.0对keep alive的支持测试

深梵 发布于 2013/01/20 12:56
阅读 890
收藏 0

在nginx的官网看的这样一则消息<url:http://nginx.org/en/docs/http/ngx_http_upstream_module.html>:

Alternatively, HTTP/1.0 persistent connections can be used by passing the “Connection: Keep-Alive” header field to an upstream server, though this is not recommended.

于是尝试下,测试架构是:用户 -> CDN nginx_A(80) -> squid(8080) ->源站nginx_B(80)

其中nginx_A的配置为:

upstream backend {
    server 127.0.0.1:8080;
}

server {
    listen      80 default;
    server_name  _;

    proxy_set_header  Host  $host;
    proxy_set_header  Connection "keep-alive";  #改写Connection头

    location / {
        proxy_pass http://backend;
    }
}

squid默认开启了对client_persistent_connections的支持。

发送一个请求,看的squid日志如下(squid combined日志格式最后附加了响应时间,请求头,响应头字段):

127.0.0.1 - - [20/Jan/2013:12:22:45 +0800] "GET http://test.squid.com/p3.jpg?test?1358655765 HTTP/1.0" 200 1052999 "-" "Wget/1.11.4 Red Hat modified" TCP_MISS:DIRECT/192.168.13.210     13 "Host: test.squid.com\r\nConnection: keep-alive\r\nUser-Agent: Wget/1.11.4 Red Hat modified\r\nAccept: */*\r\n" "HTTP/1.0 200 OK\r\nServer: nginx/1.2.6\r\nDate: Sun, 20 Jan 2013 04:22:45 GMT\r\nContent-Type: image/jpeg\r\nContent-Length: 1052565\r\nLast-Modified: Tue, 23 Oct 2012 04:07:19 GMT\r\nExpires: Mon, 21 Jan 2013 04:22:45 GMT\r\nCache-Control: max-age=86400\r\nAccept-Ranges: bytes\r\nX-Cache: MISS from vm-linux1.test.com\r\nX-Cache-Lookup: MISS from vm-linux1.test.com:8080\r\nVia: 1.1 vm-linux1.test.com:8080 (squid/2.7.STABLE9)\r\nConnection: keep-alive\r\n\r"

加深字段显示连接已经是keep-alive, 但用netstat -n或mgr:pconn, 均看到nginx_A与squid未建立持久化连接。

请教大家,在nginx向后端建立HTTP/1.0连接的前提下,怎样配置nginx与squid保持keep-alive connection?

PS: 虽然nginx最新的版本已支持对后端服务器的HTTP/1.1和keep-alive,这一点这里不讨论 

加载中
返回顶部
顶部