2016-12-23 16 views
0

私は、レート制限要求のノードサーバのプロキシとしてnginxを使用しています。レートは30秒ごとに1回のリクエストです。私はこれを引き起こしている可能性がありますかを把握することはできませんnginxへのアップストリームノードサーバのクローズ

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; 
      } 
     }  

    } 
} 

は、ノードが早期に接続を閉じることができた理由はありますか?

EDIT:NodeのビルトインHTTPサーバーを使用しています。

+0

接続を閉じるノードであれば、nginxの設定ではなくノードコードを表示する方が意味があります。 – rsp

+0

[Express.jsレスポンスタイムアウト]の可能な複製(http://stackoverflow.com/questions/21708208/express-js-response-timeout) – num8er

答えて

1

nodejsアプリケーションの応答タイムアウトを延長したようです。

それはexpressjsアプリだのであれば私はあなたがこれを試してみてください推測することができます。

インストール:npm i --save connect-timeout

使用:

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



をしかし、私は、接続待ちを維持しないようにすることをお勧めしますnodejsアプリで問題を修正して、それがなぜそんなに遅れているのかを見つけてください。

nodejs appのような問題は、応答できず、要求が失われてnginxを待機しているようです。

+1

私は急行を使用していませんが、タイムアウトに言及しました。ノードのビルトイン・サーバーには独自のタイムアウトがあるため、これをゼロに設定することが修正されました。 – Raggeth

+0

@Raggeth私の例はexpressのためのものですが、確かに、timeout属性が必要であることを伝えることでした。 Cuzは、組み込みのWebサーバーを拡張する 'connect'フレームワークに拡張されています。 – num8er

関連する問題