Proxy non persistent client connections to persistent upstream connections

I would like to be able to proxy non persistent client http connections
to
persistent upstream connections on a Linux system, both to reduce the
number of connections and the upstream latency.

I have experimented with keepalive and proxy_pass.

To observe performance I used log_format upstreamlog ‘[$time_local]
$status
$connection $connection_requests $request_time’; and $ lsof -Pni

What I think I have found is that some of the time persistent upstream
connections are reused, but very often they are not. I believe the
occasions where upstream connections are reused are possible because by
chance the client connection has been reused.

Is there a way to make this work?

Regards

Example configuration

log_format upstreamlog ‘[$time_local] $status $connection
$connection_requests $request_time’;

upstream google {
server google.com:80;
keepalive 10;
}

upstream yahoo {
server yahoo.com:80
keepalive 10;
}

server {
listen 8080;
server_name 10.0.0.1;
proxy_connect_timeout 500ms;
proxy_send_timeout 500ms;
proxy_read_timeout 500ms;
send_timeout 500ms;

location /status {
    stub_status on;
}

location /google {
    proxy_pass http://www.google.com;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Host google.com;
   access_log /var/log/google.log upstreamlog;
}

location /yahoo {
    proxy_pass http://www.yahoo.com;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Host yahoo.com;
   access_log /var/log/yahoo.log upstreamlog;
}

}

Hello!

On Mon, Aug 10, 2015 at 08:18:41AM +0000, Richard Jennings wrote:

connections are reused, but very often they are not. I believe the
occasions where upstream connections are reused are possible because by
chance the client connection has been reused.

Is there a way to make this work?

In nginx, client connections and upstream connections are not
related to each other and can be kept alive separately. That is, what
you are trying to do is how it works by design.

It doesn’t work because of an error in your config: you proxy to

    proxy_pass http://www.google.com;

and

    proxy_pass http://www.yahoo.com;

but your upstream blocks are called “google” and “yahoo”
respectively. You should use

proxy_pass http://google;

and

proxy_pass http://yahoo;

instead (or rename “upstream” blocks accordingly).


Maxim D.
http://nginx.org/

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