2016-12-23 58 views
0

我正在使用nginx作爲速率限制請求的節點服務器的代理。費率是每30秒一次請求;大多數請求返回響應罰款,但如果請求保持打開的時間過長,我得到這個:上游節點服務器關閉連接到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; 
      } 
     }  

    } 
} 

是否有一個原因,爲什麼節點可以提前關閉連接?

編輯:我使用節點的內置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應用程序有問題,無法響應和請求正在丟失保持nginx等待。

+1

我沒有使用快遞,但您提到超時;節點的內置服務器有其自己的超時,所以將其設置爲零是修復。 – Raggeth

+0

@Raggeth我的例子是爲了表達,但是想法是告訴你它應該有timeout屬性。 Cuz express本身擴展到擴展內置web服務器的'connect'框架。 – num8er

相關問題