簡體   English   中英

上游節點服務器關閉與Nginx的連接

[英]Upstream Node server closing connection to 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服務器。

似乎您必須延長nodejs應用程序的響應超時。

因此,如果它是expressjs應用程序,那么我可以猜測您可以嘗試以下方法:

安裝: npm i --save connect-timeout

采用:

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



但是我建議不要讓連接等待並修復nodejs應用程序中的問題,找出為什么它停頓了這么長時間。

好像nodejs應用程序有無法響應的問題,並且讓nginx等待的請求丟失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM