Estou tentando usar o nginx em uma máquina virtual centos 7 como um balanceador de carga para substituir um dispositivo de hardware antigo do Coyote Point. No entanto, em um de nossos aplicativos da web, estamos vendo erros freqüentes e contínuos de tempo limite de upstream nos logs e os clientes estão relatando problemas de sessão durante o uso do sistema.
Aqui estão os bits relevantes do nosso nginx.conf
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
upstream farm {
ip_hash;
server www1.domain.com:8080;
server www2.domain.com:8080 down;
server www3.domain.com:8080;
server www4.domain.com:8080;
}
server {
listen 192.168.1.87:80;
server_name host.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 192.168.1.87:443 ssl;
server_name host.domain.com;
## Compression
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 4;
gzip_http_version 1.0;
gzip_min_length 1280;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp;
gzip_vary on;
tcp_nodelay on;
tcp_nopush on;
sendfile off;
location / {
proxy_connect_timeout 10;
proxy_send_timeout 180;
proxy_read_timeout 180; #to allow for large managers reports
proxy_buffering off;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://farm;
location ~* \.(css|jpg|gif|ico|js)$ {
proxy_cache mypms_cache;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_cache_valid 200 60m;
expires 60m;
proxy_pass http://farm;
}
}
location /basic_status {
stub_status;
}
error_page 502 502 = /maintenance.html;
location = /maintenance.html {
root /www/;
}
}
Nos registros, frequentemente vejo entradas como
2015/03/13 15:22:58 [error] 4482#0: *557390 upstream timed out (110: Connection timed out) while connecting to upstream, client: 72.160.92.101, server: host.domain.com, request: "GET /tapechart.php HTTP/1.1", upstream: "http://192.168.1.50:8080/tapechart.php", host: "host.domain.com", referrer: "https://host.domain.com/tapechart.php"
2015/03/13 15:23:14 [error] 4481#0: *557663 upstream timed out (110: Connection timed out) while connecting to upstream, client: 174.53.144.4, server: host.domain.com, request: "GET /bkgtabs.php?bookingID=3105543&show=0 HTTP/1.1", upstream: "http://192.168.1.50:8080/bkgtabs.php?bookingID=3105543&show=0", host: "host.domain.com", referrer: "https://host.domain.com/bkgtabs.php?bookingID=3105543&show=0"
2015/03/13 15:23:19 [error] 4481#0: *557550 upstream timed out (110: Connection timed out) while connecting to upstream, client: 50.134.133.213, server: host.domain.com, request: "GET /tbltapechart.php?numNights=30&startDate=1-Aug-2015&roomTypeID=-1&hideNav=N&bookingID=&roomFilter=-1 HTTP/1.1", upstream: "http://192.168.1.50:8080/tbltapechart.php?numNights=30&startDate=1-Aug-2015&roomTypeID=-1&hideNav=N&bookingID=&roomFilter=-1", host: "host.domain.com", referrer: "https://host.domain.com/tapechart.php"
2015/03/13 15:23:37 [error] 4483#0: *561705 upstream timed out (110: Connection timed out) while connecting to upstream, client: 74.223.167.14, server: host.domain.com, request: "GET /js/multiselect/jquery.multiselect.filter.css HTTP/1.1", upstream: "http://192.168.1.55:8080/js/multiselect/jquery.multiselect.filter.css", host: "host.domain.com", referrer: "https://host.domain.com/fdhome.php"
2015/03/13 15:23:40 [error] 4481#0: *561099 upstream timed out (110: Connection timed out) while connecting to upstream, client: 74.223.167.14, server: host.domain.com, request: "GET /img/tabs_left_bc.jpg HTTP/1.1", upstream: "http://192.168.1.55:8080/img/tabs_left_bc.jpg", host: "host.domain.com", referrer: "https://host.domain.com/fdhome.php"
2015/03/13 15:23:45 [error] 4481#0: *557214 upstream timed out (110: Connection timed out) while connecting to upstream, client: 75.37.141.182, server: host.domain.com, request: "GET /tapechart.php HTTP/1.1", upstream: "http://192.168.1.50:8080/tapechart.php", host: "host.domain.com", referrer: "https://host.domain.com/tapechart.php"
2015/03/13 15:23:52 [error] 4482#0: *557330 upstream timed out (110: Connection timed out) while connecting to upstream, client: 173.164.149.18, server: host.domain.com, request: "GET /bkgtabs.php?bookingID=658108460B&show=1&toFolioID=3361434 HTTP/1.1", upstream: "http://192.168.1.50:8080/bkgtabs.php?bookingID=658108460B&show=1&toFolioID=3361434", host: "host.domain.com", referrer: "https://host.domain.com/bkgtabs.php?bookingID=658108460B&show=1&toFolioID=3361434"
2015/03/13 15:24:14 [error] 4481#0: *557663 upstream timed out (110: Connection timed out) while connecting to upstream, client: 174.53.144.4, server: host.domain.com, request: "GET /bkgtabs.php?bookingID=3105543&show=0 HTTP/1.1", upstream: "http://192.168.1.50:8080/bkgtabs.php?bookingID=3105543&show=0", host: "host.domain.com", referrer: "https://host.domain.com/bkgtabs.php?bookingID=3105543&show=0"
2015/03/13 15:24:15 [error] 4481#0: *557752 upstream timed out (110: Connection timed out) while connecting to upstream, client: 24.158.4.70, server: host.domain.com, request: "GET /bkgtabs.php?bookingID=2070569 HTTP/1.1", upstream: "http://192.168.1.50:8080/bkgtabs.php?bookingID=2070569", host: "host.domain.com", referrer: "https://host.domain.com/tapechart.php"
2015/03/13 15:24:15 [error] 4482#0: *558613 upstream timed out (110: Connection timed out) while connecting to upstream, client: 199.102.121.3, server: host.domain.com, request: "GET /rptlanding.php HTTP/1.1", upstream: "http://192.168.1.50:8080/rptlanding.php", host: "host.domain.com", referrer: "https://host.domain.com/tapechart.php"
2015/03/13 15:24:17 [error] 4482#0: *557353 upstream timed out (110: Connection timed out) while connecting to upstream, client: 174.53.144.4, server: host.domain.com, request: "GET /js/multiselect/demo/assets/prettify.js HTTP/1.1", upstream: "http://192.168.1.50:8080/js/multiselect/demo/assets/prettify.js", host: "host.domain.com", referrer: "https://host.domain.com/bkgtabs.php?bookingID=3186044"
Inicialmente, descobri que precisava definir um proxy_read_timeout tão alto porque temos 1 relatório muito grande e demora pelo menos 20 segundos para renderizar totalmente para usuários com um conjunto de dados moderado. Nossos usuários com o maior conjunto de dados podem levar até dois minutos para gerar o relatório. No entanto, é muito raramente executado, geralmente menos de uma vez por dia por usos e nunca foi o URL na seqüência GET nos logs.
Os quatro servidores back-end são servidores Apache idênticos, todos rodando o httpd 2.2.29 e o php 5.5.22 construídos a partir da fonte e todos estão na mesma versão do centos e atualizados. Como eu tinha visto originalmente um hit do MaxClients nos logs, defini o seguinte em cada host do Apache
<IfModule mpm_prefork_module>
StartServers 10
MinSpareServers 10
MaxSpareServers 20
MaxClients 200
MaxRequestsPerChild 300
</IfModule>
O servidor nginx e os servidores apache estão todos localizados no mesmo datacenter, na mesma sub-rede e vlan e não vejo nada no error_log no lado do servidor apache indicando um motivo para os tempos limite.
Outras coisas que tentamos solucionar isso incluem
- Aumentando o proxy_read_timeout para 300.
- Removendo as configurações do Gzip.
- Removendo o bloco de localização para css, imagens e cache de javascript.
- Ativando proxy_buffering. Ele está desativado devido ao grande relatório para permitir que o nginx comece a exibi-lo como renderizado (incluindo um indicador de progresso de javascript de relatório de construção) em vez de exibir uma página em branco por 20 a 120 segundos.
- Adicionando o KeepAlive 8/16/32/64 ao upstream.
Neste ponto, estou duvidoso que seja um problema de rede ou um problema com o backend, já que mudei a aplicação web de volta para o balanceador de carga do ponto coiote e as reclamações caíram.
Eu realmente adoraria descobrir isso, mas estou meio confuso sobre aonde ir a partir daqui. Conselho por favor?