上游节点服务器关闭与Nginx的连接

拉格斯

我将nginx用作速率限制请求的节点服务器的代理。速率是每30秒请求一次;大多数请求返回的响应都很好,但是如果请求长时间保持打开状态,我会得到以下信息:

upstream prematurely closed connection while reading response header from upstream

我不知道是什么原因造成的。下面是我的nginx配置:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
# include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

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

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /srv/www/main/htdocs;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;    

        location /vcheck {
            proxy_pass http://127.0.0.1:8080$is_args$query_string;
            # proxy_buffer_size 128k;
            # proxy_buffers 4 256k;
            # proxy_busy_buffers_size 256k;
            # proxy_http_version 1.1;
            # proxy_set_header Upgrade $http_upgrade;
            # proxy_set_header Connection 'upgrade';
            # proxy_set_header Host $host;
            # proxy_cache_bypass $http_upgrade;         
            # proxy_redirect off;

            proxy_read_timeout 600s;
        }

        location ~ \.php$ {
            include fastcgi.conf;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index routes.php$is_args$query_string;
        }

        location / {
            if (-f $request_filename) {
                expires max;
                break;
            }

            if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css)$") {
                rewrite ^(.*) /routes.php last;
            }
        }       

    }
}

为什么Node可能会提早关闭连接?

编辑:我正在使用Node的内置HTTP服务器。

num8er

似乎您必须延长nodejs应用程序的响应超时。

因此,如果它是expressjs应用程序,那么我可以猜测您可以尝试以下一种方法:

安装: npm i --save connect-timeout

用:

var timeout = require('connect-timeout');
app.use(timeout('60s'));



但是我建议不要一直保持连接等待状态并修复nodejs应用程序中的问题,请找出为什么它停顿了这么长时间。

似乎nodejs应用程序存在无法响应的问题,并且使nginx等待的请求丢失了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误:连接丢失:服务器关闭了连接。mysql 节点

Nginx代理上游服务器Docker Compose-拒绝502错误的网关连接

Nginx proxy_reverse 和节点服务器。你在哪里看到上游节点服务器的控制台日志输出?

Nginx上游到Express服务器-502错误

是否可以让上游服务器在 Nginx 服务器后面处理 SSL 证书?

Mitmproxy上游服务器

使用AWS ELB的连接节点服务器闲置60秒后Websocket关闭

使用 NGINX 的节点服务器

读取直到服务器关闭连接

phpseclib 连接被服务器关闭?

服务器关闭MTProto连接

nginx使节点红色失去与服务器的连接,但可以部署

连接已关闭:多个节点应用程序使用Mongoose连接到同一MongoDB服务器

NGINX API 网关 - NGINX 是否转发到上游服务器

nodejs mysql错误:连接丢失服务器关闭了连接

尝试SSL连接时服务器强制关闭连接

节点服务器 http 关闭事件总是触发

如何将位置映射到Nginx中的上游服务器?

nginx-从上游服务器读取自定义标头

如何在nginx OSS上动态重新配置上游服务器?

同一台服务器上的nginx上游子域

更新上游服务器时,重新启动Nginx容器

TCP代理到Postgres数据库作为Nginx中的上游服务器

当上游服务器再次被代理时,Nginx 健康检查会起作用吗?

如何在Nginx配置的上游块中公开服务器端口?

三分之一的 Nginx 路由忽略上游服务器

使用 Tarantool http 作为 Nginx 上游服务器 - 出现错误 13:权限被拒绝

nginx 在同一台服务器上缓存几个上游

AWS ECS jwilder/nginx-proxy 无法在上游生成服务器