75秒后,在nginx访问日志中出现了大量的499状态码。

我们在长轮询场景中使用 nginx。我们有一个用户安装的客户端,然后与我们的服务器通信。服务器中的一个 nginx 进程将该请求传递给 Python 进程作为后端。Python 进程最多保持请求 650 秒。

在 nginx 访问日志中有很多 499 项。记录 $request_time 显示客户端在 75 秒后超时。但 nginx 的任何超时都不设置为 75 秒。

一些研究表明后端进程可能过慢,但是包含进程的服务器上并没有太多活动。添加更多服务器/进程也没有帮助,升级 nginx 所在的实例也没有帮助。

以下是 nginx 配置文件。

nginx.conf

user nobody nogroup;
worker_processes 1;
worker_rlimit_nofile 131072;
pid /run/nginx.pid;

events {
       worker_connections 76800;
}

http {

       sendfile on;
       tcp_nopush on;
       tcp_nodelay on;
       types_hash_max_size 2048;
       keepalive_timeout 65;

       server_names_hash_bucket_size 64;

       include /usr/local/openresty/nginx/conf/mime.types;
       default_type application/octet-stream;

log_format combined_edit '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent" "$request_time"';

       access_log /var/log/nginx/access.log combined_edit;
       error_log /var/log/nginx/error.log;

       gzip on;
       gzip_disable "msie6";

       include /usr/local/openresty/nginx/conf.d/*.conf;
       include /usr/local/openresty/nginx/sites-enabled/*;
}

backend.conf

upstream backend {
  server xxx.xxx.xxx.xxx:xxx max_fails=12 fail_timeout=12;
  server xxx.xxx.xxx.xxx:xxx max_fails=12 fail_timeout=12;
}

server {
  listen 0.0.0.0:80;
  server_name host;
  rewrite ^(.*) https://$host$1 permanent;
}

server {
  listen 0.0.0:443;
  ssl_certificate /etc/ssl/certs/ssl.pem;
  ssl_certificate_key /etc/ssl/certs/ssl.pem;
  ssl on;
  server_name host;
  location / {
    proxy_connect_timeout 700;
    proxy_buffering off;
    proxy_redirect off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_read_timeout 10000; # something really large
    proxy_pass http://backend;
  }
}
点赞