Welcome! Log In Create A New Profile

Advanced

nginx proxy_cache зависание соединения с upstream

March 26, 2012 04:12PM
Добрый вечер.

Столкнулся со следующей проблемой:

nginx работает как кеширующий reverse proxy. Соединение с upstream по HTTP/1.0.

Версия:
nginx: nginx version: nginx/1.0.6
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
nginx: TLS SNI support disabled
nginx: configure arguments: --user=nginx --group=nginx --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_secure_link_module --with-http_random_index_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-ipv6 --with-file-aio --add-module=/opt/rpmbuild/BUILD/nginx-1.0.6/nginx-upstream-fair --add-module=/opt/rpmbuild/BUILD/nginx-1.0.6/nginx-upload-progress-module --add-module=/opt/rpmbuild/BUILD/nginx-1.0.6/mod_zip-1.1.6 --add-module=/opt/rpmbuild/BUILD/nginx-1.0.6/nginx_upload_module-2.2.0 --add-module=/opt/rpmbuild/BUILD/nginx-1.0.6/nginx_mod_h264_streaming-2.2.7 --add-module=/opt/rpmbuild/BUILD/nginx-1.0.6/ngx_http_bytes_filter_module

Выдержка из конфигурации:
location ~ \.bin
{
proxy_buffering off;
proxy_buffer_size 8k;
proxy_buffers 4 8k;
proxy_intercept_errors on;

proxy_pass http://srv;
proxy_redirect off;

proxy_next_upstream error timeout;
proxy_temp_path /path/to/tmp;

proxy_cache cache_name;
proxy_cache_key $scheme://$proxy_host$request_uri;
proxy_cache_min_uses 1;
proxy_cache_valid 200 10s;
proxy_cache_valid any 1s;

proxy_set_header Host example.ru;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-CDN-URL $server_name$request_uri;

proxy_ignore_headers Expires Cache-Control;

proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_connect_timeout 15s;
proxy_read_timeout 15s;
proxy_send_timeout 15s;
}


При запросе к upstream он получает все запрошенные данные, но НЕ! закрывает соединение и его закрывает upstream через определенный временной промежуток (порядка 10 секунд).

Выдержка из tcpdump(x.x.x.x - nginx, y.y.y.y - upstream):

21:40:11.249035 IP x.x.x.x.52046 > y.y.y.y.24035: S 2248427822:2248427822(0) win 11680
21:40:11.249800 IP y.y.y.y.24035 > x.x.x.x.52046: S 3332218283:3332218283(0) ack 2248427823 win 34752
21:40:11.249835 IP x.x.x.x.52046 > y.y.y.y.24035: . ack 1 win 3
21:40:11.249919 IP x.x.x.x.52046 > y.y.y.y.24035: P 1:373(372) ack 1 win 3
21:40:11.250744 IP y.y.y.y.24035 > x.x.x.x.52046: . ack 373 win 9
21:40:11.253192 IP y.y.y.y.24035 > x.x.x.x.52046: P 1:172(171) ack 373 win 9
21:40:11.253239 IP x.x.x.x.52046 > y.y.y.y.24035: . ack 172 win 3
21:40:11.254042 IP y.y.y.y.24035 > x.x.x.x.52046: P 172:410(238) ack 373 win 9
21:40:11.254070 IP x.x.x.x.52046 > y.y.y.y.24035: . ack 410 win 3
21:40:20.536249 IP y.y.y.y.24035 > x.x.x.x.52046: F 410:410(0) ack 373 win 9
21:40:20.536654 IP x.x.x.x.52046 > y.y.y.y.24035: F 373:373(0) ack 411 win 3
21:40:20.537349 IP y.y.y.y.24035 > x.x.x.x.52046: . ack 374 win 9


Предполагал, что проблема в сохранении на диск. Разместил tmp и cache в tmpfs - эффекта нет.

Если уменьшить proxy_read_timeout до 5 секунд, то в логах появляется ошибка upstream timed out (110: Connection timed out) while reading upstream и ответ приходит не полный.

Если установить proxy_buffering off, то все работает корректно:
23:42:08.178855 IP x.x.x.x.57337 > y.y.y.y.24035: S 1378610853:1378610853(0) win 11680
23:42:08.190725 IP y.y.y.y.24035 > x.x.x.x.57337: S 2454105719:2454105719(0) ack 1378610854 win 34752
23:42:08.190769 IP x.x.x.x.57337 > y.y.y.y.24035: . ack 1 win 3
23:42:08.190821 IP x.x.x.x.57337 > y.y.y.y.24035: P 1:373(372) ack 1 win 3
23:42:08.191731 IP y.y.y.y.24035 > x.x.x.x.57337: . ack 373 win 9
23:42:08.408412 IP y.y.y.y.24035 > x.x.x.x.57337: P 1:172(171) ack 373 win 9
23:42:08.408460 IP x.x.x.x.57337 > y.y.y.y.24035: . ack 172 win 3
23:42:08.409164 IP y.y.y.y.24035 > x.x.x.x.57337: P 172:410(238) ack 373 win 9
23:42:08.409196 IP x.x.x.x.57337 > y.y.y.y.24035: . ack 410 win 3
23:42:08.409449 IP x.x.x.x.57337 > y.y.y.y.24035: F 373:373(0) ack 410 win 3
23:42:08.413223 IP y.y.y.y.24035 > x.x.x.x.57337: F 410:410(0) ack 374 win 9
23:42:08.413253 IP x.x.x.x.57337 > y.y.y.y.24035: . ack 411 win 3


nginx закрывает соединение, но необходимо кеширование.
Как заставить nginx закрывать соединение с upstream сразу после прочтения данных от него и при этом не выключать кеширование?
Subject Author Posted

nginx proxy_cache зависание соединения с upstream

vovanhost March 26, 2012 04:12PM

Re: nginx proxy_cache зависание соединения с upstream

vovanhost March 27, 2012 01:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 221
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready