Nginx loading page very slow

nginxperformance

I just deployed nginx in a new environment with the same configuration that I've used previously and I am seeing some very odd behavior.

Nginx is configured as a reverse proxy for Solr, when I try to access the Solr UI through nginx, it takes about a minute to load. I checked Chrome dev tools and it looks like the browser is able to download 6 files right off the bat, however then all other requests are in a pending status. Then it just sits there for exactly a minute and after that everything gets downloaded and page loads. After that, the browsing is fast; I think this is mainly because of local browser cache.

Here is the config:

worker_processes  10;
error_log  /directory/path/error.log debug;
pid        /directory/path/nginx1.pid;

events {
     worker_connections  1024;
}

http {
 access_log  /directory/path/access.log;
 proxy_temp_path /directory/path/ 1 2;

upstream backend-test-old {
    server 1.1.1.1:7071;
    server 2.2.2.2:7071;
}

server {
    listen       7071;
    server_name  localhost;
    access_log /directory/path/access_7071.log;
    proxy_ignore_headers "Set-Cookie";
    proxy_hide_header "Set-Cookie";
    location /solr {
        proxy_pass http://backend-test-old;
    }
}
}

I also see a lot of these in the logs:

2015/07/10 11:06:38 [warn] 31503#0: *120 an upstream response is buffered to a temporary file /dir/path/7/00/0000000007 while reading upstream, client: 111.111.111.111
2015/07/10 11:06:36 [info] 31503#0: *96 client prematurely closed connection, so upstream connection is closed too while connecting to upstream, 
2015/07/10 11:06:36 [error] 31503#0: *101 upstream timed out (110: Connection timed out) while connecting to upstream, client:

Now this is not a problem on my dev server, which runs the same config and should be configured relatively similar, so it could be something system related, but I am not sure.

Any help would be much appreciated.

Thanks

EDIT:

It looks like the issue is me pointing to back end hosts by IP vs hostname. I am not sure why this is an issue. I've implemented this config:

worker_processes  10;
error_log  /path/error.log debug;
pid        /path/nginx1.pid;

events {
    worker_connections  1024;
}

http {
     access_log  /path/access.log;
     proxy_temp_path /pathproxy_temp/ 1 2;

    upstream backend-test-old {
        server hostname-for-1.1.1.1:7071;
        server hostname-for-2.2.2.2:7071;
    }

    upstream backend-test-old2 {
        server 1.1.1.1:7071;
        server 2.2.2.2:7071;
    }

    server {
        listen       7071;
        server_name  localhost;
        access_log /path/access_7071.log;
        proxy_ignore_headers "Set-Cookie";
        proxy_hide_header "Set-Cookie";
        location /solr {
                proxy_pass http://backend-test-old;
        }
    }

        server {
        listen       7072;
        server_name  localhost;
        access_log /path/access_7072.log;
        proxy_ignore_headers "Set-Cookie";
        proxy_hide_header "Set-Cookie";
        location /solr {
                proxy_pass http://backend-test-old2;
        }
    }
}

If I go through 7071 it works fine, however if I hit through 7072 the performance problem described above occurs. Does anyone have any ideas?

Best Answer

The buffering causes problems there, turn it off completely:

proxy_buffering off;

See the official docs for details:

When buffering is disabled, the response is passed to a client synchronously, immediately as it is received. nginx will not try to read the whole response from the proxied server. The maximum size of the data that nginx can receive from the server at a time is set by the proxy_buffer_size directive.